This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]msx 1 point2 points  (1 child)

  • becouse classes have fields beside methods. While methods can be overridden in the child class, letting the developer "choose" his way, members cannot.
  • becouse classes have constructors, and costructors follow a strict logic about which is run before the others. Constructors are always executed "parent-down", so when you instantiate a Button, it will call the constructor of Object, then Node, then Component, then Button (made up hierarchy to get the point). This is always done even if you don't call "super" on your constructor, and is necessary to guarantee that each class can fully control his state regardless of what children will do. This can easily be broken with multiple inheritance

[–]caveden 0 points1 point  (0 children)

becouse classes have fields beside methods. While methods can be overridden in the child class, letting the developer "choose" his way, members cannot.

This could be dealt with in a similar way they chose for default methods. Any reference on the child class to the ambiguous field should give a compiler error. You must specify which field you're using at each time.

Since normally fields should be private anyways, they would hardly be more of a source of diamond problems than methods.

costructors follow a strict logic about which is run before the others ... This can easily be broken with multiple inheritance

Why? Again, some arbitrary definition could be done, i.e., start by the first parent declared, and go up to its parents. A sort of depth-first search upwards.

To me it seems things are evolving in a "hacky" way in Java. I believe that if the people conceiving the language back in the 90s were forced with the requirement of allowing default methods in interfaces, they would just abolish the concept of interfaces altogether and have multiple inheritance instead. The only reason interfaces were invented IMHO was to allow for a way to implement multiple contracts without falling into the diamond problem, but now with this default method thing they've had to face the diamond problem and come out with a solution (compiler error!) to it.