Is classOf [] in Scala 2.8 different from 2.7?

I have an interface from Java

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

Inherited in Scala

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

He 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.Classin Scala 2.8?

+3
source share
2 answers

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

+6
source

annotate return type java.lang.Class [Foo]

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

this is normal.

But the method signature is changed by subclass. Interesting!

+1

Source: https://habr.com/ru/post/1741570/


All Articles