views:

130

answers:

2

I have an interface from Java

public class IJava
{
   ...
   public java.lang.Class getType();
   ...
}

It is inherited in Scala

class CScala
{
    def getType() = classOf[Foo]
}

It worked in Scala 2.7.7. But in 2.8.0.RC1, I get

type mismatch;  found   : java.lang.Class[Foo](classOf[Foo])  
required: java.lang.Class

How do I get java.lang.Class in Scala 2.8?

+6  A: 

Try to annotate the return type of getType() as java.lang.Class. The problem here is that you are using a raw type on the interface, and raw types really don't work well with Scala.

Daniel
+1  A: 

annotate the return type java.lang.Class[Foo]

class CScala { def getType() : java.lang.Class[Foo] = classOf[Foo] }

it is ok.

But, the method signature is changed by subclass. Interesting!

redtank