TL;TD In Java 8, is there a way for an interface default method to access instance variables?
For instance:
public interface Foo{
default getBazModified(){
return baz * 2;
}
}
public class Bar implements Foo {
int baz;
...
}
I know that sounds like travisty but is there a way to do anything like that in Java 8?
Or is the only way is to have an abstract class that implements Foo, which would have both the instance variable baz declared and have a default implementation of getBazModified()?
default int getBazModified(int baz){ return baz * 2; }
, what's the challenge there? since anyway you call an instance method which would have its ownbaz
value that it can pass on the invocation of this method. – Nagey