Fork me on GitHub

Graceless Failures

Tips, tricks, missteps, and minor revelations on the path to Scala wisdom.

Class What?

I’m a little annoyed that this doesn’t work:

scala> class Foo
defined class Foo

scala> object Thing extends Foo
defined module Thing

scala> val set = scala.collection.immutable.Set[Class[_ <: Foo]](Thing.getClass)
<console>:6: error: type mismatch;
 found   : java.lang.Class[?0] where type ?0
 required: Class[_$1] forSome { type _$1 <: Foo }
       val set = scala.collection.immutable.Set[Class[_ <: Foo]](Thing.getClass)
                                                                       ^

I’m sure it’s probably a java compatibility thing, but shouldn’t the class of an object of type T return a class of type Class[T]?