How to create a map with a class type parameter
I am 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 does not work. What type parameter should I use for the class?
0
a source to share
1 answer
I'm not really sure what the main problem is, but it's not a type parameter for the class. Looks like some weird output type problem with "->". The following compiles and works 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 you were talking about.
I submitted a ticket in case hoping this is something fixed: https://lampsvn.epfl.ch/trac/scala/ticket/1974 .
+3
a source to share