Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About New Interface Default Methods

 
mustafa yildirim
Greenhorn
Posts: 2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know that java 8 contains multi inheritance because of default method feature from now on. How do diamond problem arise. We should becareful of which cases not to face these situations. So, could you please share your thoughts and advices.
Regards
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3817
10
 
Simon Roberts
Author
Ranch Hand
Posts: 170
7
Java Linux Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mustafa yildirim wrote:You know that java 8 contains multi inheritance because of default method feature from now on. How do diamond problem arise. We should becareful of which cases not to face these situations. So, could you please share your thoughts and advices.
Regards


From the Java Programmer 1 exam perspective, this isn't covered. I don't recall it showing up in the Programmer II either come to think of it, but technically, it could be thought of as being part of the objectives, given that they're written pretty vaugely.

From a design perspective, "they say" that default methods are intended for the extension of _existing_interfaces_, so shouldn't become a problem very often. Of course, "they contradict themselves" because there are default methods in some of the brand new functional interfaces (but they're also not part of the SE 8 Programmer 1 exam.) So, yeah, handle with care for sure!

As to _how_ it works (which you didn't ask, I think, but maybe you did), I think the previous answer covers this well. In a nutshell, if the problem arises then 1) the class always beats the interface definition, 2) the "closest" interface definition wins 2) if you have two interface definitions at the same "distance" then you must manually define the target method and choose how to implement it. You can, if you chose, delegate to one of the parent definitions.

Cheers,
Simon
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's weird that the Multiple Inheritance of State, Implementation, and Type section of the Oracle Java Tutorials doesn't explain how multiple inheritance of implementation is handled by the compiler. But I like the explanation about the difference between multiple inheritance of state (with classes, not allowed) and multiple inheritance of implementation (with interfaces, allowed).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic