Reputation: 3155
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
}
Upvotes: 3
Views: 724
Reputation: 7957
You cannot access the foo
field because it's private. You can only access it by super.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.
Upvotes: 7