tags:

views:

88

answers:

1

I'm trying to do something like this:

import scala.swing

class componentMapper {

     val map = Map[Class[_], Componenet]()

     def apply(c: Class[_], component: Component) = map += (c -> componenet)

}

class Render extends ComponentMapper {

     def getRenderer(value: AnyRef) = map(value.getClass)

}

This doesn't seem to work. What type parameter should I be using for Class?

+3  A: 

I'm not entirely sure what the core problem is, but it's not the type parameter for class. It appears to be some weird type inference issue with "->". The following compiles and works just fine.

import scala.swing._

class ComponentMapper {
  var map = Map[Class[_], Component]()
  def apply(c: Class[_], component: Component) = map += ((c, component))
}

class Render extends ComponentMapper {
  def getRenderer(value: AnyRef) = map(value.getClass)
}

Note that I had to make many small corrections to your code to even find what problem you were talking about.

I've filed a ticket in case in hopes that it's something fixable: https://lampsvn.epfl.ch/trac/scala/ticket/1974.

James Iry
Excellent, that works. Thanks.
Brian