I want to extend a class which is implemented in Java. Here is an example:
public interface JavaInterface {
/** Computes foo. */
public String foo();
}
public class ThisIsJava implements JavaInterface {
protected String foo = "foo";
/** Returns value of property foo. */
public String foo() { return foo; }
}
But how do I disambiguate between the field and the method foo when I extend this class in Scala?
class ThisIsScala extends ThisIsJava {
def fooBar = super.foo + "/bar" // doesn't compile
}
You cannot access the
foofield because it’s private. You can only access it bysuper.foo().Update: I think you have this problem because in Scala there is no distinction between fields and methods, so the only option option would be to have an adapter for ThisIsJava, and extend that adapter in Scala.