I've got a Scala Trait with a method that returns Option[Boolean]. I'd like to write a Java class that implements this trait. Unfortunately the compiler complains about the following code:
trait WithBoolean {
def doSth(): Option[Boolean]
}
public class MyClass implements WithBoolean {
@Override
public Option<Boolean> doSth() {
return null;
}
}
The compile error is:
doSth() in MyClass cannot implement doSth() in WithBoolean
public Option<Boolean> doSth() {
^
return type Option<Boolean> is not compatible with Option<Object>
It does compile if i change the code slightly:
public class MyClass implements WithBoolean {
@Override
public Option<Object> doSth() { //return type has been changed to Object
return null;
}
}
But this is obviously not a nice solution. What do I need to change in order to be able to use the correct return type?