Is classOf[] in Scala 2.8 different from 2.7?
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?
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.
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!
精彩评论