From: Clifford Heath on
Robert Klemme wrote:
> Wouldn't that mean duplicate entries for a method which is part of
> several interfaces?

Yes, but the compiler knows which interface it wants,
so there's no ambiguity. Dynamic binding only occurs
at the interface level. Once you have the interface,
getting the method is just a table lookup.

> And what happens in case of interface inheritance?

Each interface requires a single set of methods, whether
through declaration or inheritance, so there's no need
for a special case.

Clifford Heath.
From: David Masover on
On Tuesday, July 20, 2010 12:25:03 am Robert Klemme wrote:
> On 20.07.2010 06:03, David Masover wrote:
> > In fact, IIRC, this is how C++ does it -- it's just made much easier due
> > to multiple inheritance. I never quite understood why Java allows
> > multiple interfaces to be applied to the same object, and even to the
> > same interface, but not multiple inheritance.
>
> State. I guess they were afraid of the way C++ makes inheritance
> complicated because of virtual and non virtual inheritance and the
> consequences for the visibility of state ("diamond problem").

It seems like this exact problem exists just as much in an interface, though
-- the only difference is that interfaces force implementations to explicitly
implement each of their methods. The simple solution, then, would be to force
the inheriting class to explicitly override those methods.

Actual, direct state -- as in, instance variables -- I don't see any reason
for an instance variable to be anything other than private, except for the
fact that Java makes setters and getters ridiculously verbose.

> I would
> also add that "interface" is a cleaner concept because it stresses the
> fact that not behavior or state is shared but only the interface.

I agree that it's cleaner, but it's also something which could easily be done
by convention, as you suggest:

> Granted, you can achieve similar goals with abstract classes that
> contain only abstract methods

A Java Interface is essentially an abstract class, which contains only
abstract methods, but which can be multiply inherited from.