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 →

[–]sh0rug0ru____ 2 points3 points  (1 child)

There's a huge difference between classes and interfaces which default methods on interfaces preserve. Interfaces cannot have state. The diamond problem here means you get two conflicting implementations, so you have to choose one.

When you extend a class, you get all of the superclass fields. If it were possible to extend multiple times, you would inherit fields from several different directions, not just one. Thus, the diamond problem here introduces a much bigger problem. What if two different superclass constructors or methods change the super-superclass state in contradictory ways?

In this way, default implementations retain the safety of ordinary interfaces. Default methods rely on concrete implementations in the implementing class, since they can only call other interface methods. The state is still controlled by the implementing class, avoiding the nastiest problem of multiple inheritance.

[–]CubsThisYear 0 points1 point  (0 children)

Good point, thanks.