3 ms·
The idea of 'default methods' looks quite disturbing. It seems to allow implementation of some methods inside interfaces. Which is against the basic idea of int
by mbel 14y ago
The idea of 'default methods' looks quite disturbing. It seems to allow implementation of some methods inside interfaces. Which is against the basic idea of interface, isn't it?
Correct me if I'm wrong, but multiple inheritance problems form C++ are now going to be a brand new feature in Java.
- mccoyst 14y agoThere's no difference between implementing method dispatch with multiple inheritance versus multiple interfaces. What do you think C++'s multiple inheritance problems are? As long as Oracle doesn't add data members to interfaces, Java won't get any new problems.
- mbel 14y agoI might be missing something, but what I see as a problem is a situation where: class C implements interfaces IA and IB, which both contain method doSomething() with default implementations, class C doesn't overrides this method, so which implementation is going to be called when method doSomething() will be invoked on instance of C? Will it behave the same way if it is called as instance of C and as instance of IA or IB? Clearly, there are rules in C++ to handle such situations, one may argue that they are problematic.
- spullara 14y agoIf there is no way to break the ambiguity the compilation will fail and you will have to override that method (in 8.4.8.4 of the spec). You can use IA.super or IB.super to call one of the default methods if one of them works for you and you don't need your own bespoke implementation.
- mbel 14y agoThanks for clarifying; although I don't really like this feature, compilation failure seems to be the best solution (and well I guess I should have RTFM to begin with, sorry).
- coopdog 14y agoIf it's an interface you have to override the method. An abstract class you don't, but you can only inherit one anyway.
- Sandman 14y agoI agree with you. There is a reason why classes in Java can only inherit implementations of methods from a single parent class. If we're going down this road, why not just allow multiple inheritance?