Re: multiple inheritance in Java
On 03/07/13 14:12, Steven Simpson wrote:
On 03/07/13 13:01, lipska the kat wrote:
It is possible to add state to an interface so that it is *almost* a
class [...]
interface Foo{
/* explicitly static and final */
Integer i = 0;
State state = new State(); /* final reference, mutable instance */
default public void doFoo(Integer x){
//i = 10; /* illegal */
Integer y = x + i;
state.a = y + y;
System.out.println("doingFoo, i + x is " + y);
System.out.println("doingFoo, accessing state state.a is " +
state.a);
}
}
Foo.state is effectively class state, rather than instance state, isn't
it? Some possibilities were discussed here:
<http://mail.openjdk.java.net/pipermail/lambda-dev/2012-July/005165.html>
I don't know, I've only recently started looking at this.
IIUC (which is by no means certain at this point) then state is a class
variable that is shared by all instances of all classes that implement
the Foo interface ... or is it a class variable that is shared by all
instances of a given class that implements Foo and a different class
that implements Foo would have it's own copy of state shared by all it's
instances ... that seems more likely, I suppose some more investigation
is required
I can't say I've ever really had much use for variables in interfaces
before so I've never really given this sort of thing much thought.
lipska
--
Lipska the Kat?: Troll hunter, sandbox destroyer
and farscape dreamer of Aeryn Sun