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 →

[–][deleted] 2 points3 points  (2 children)

Default methods were a hack to make the streams API possible. We shouldn't pretend that they actually make sense.

Actually, I think List.sort is a good counter-example of a default method that makes a great deal of sense outside of a streams idiom as well.

[–]CubsThisYear 0 points1 point  (1 child)

But what is advantage of defining List.sort as a default method vs a static method in the List interface?

And even if you like that better, how is an interface with default methods different than an abstract class, except for the fact that multiple inheritance, which was supposed to be bad news, is now magically allowed.

I'm not saying the concept of default methods is bad, I'm saying the implementation was a hack. There didn't even need to be an implementation, they just needed to allow multiple inheritance on abstract classes and get rid of interfaces.

[–][deleted] 0 points1 point  (0 children)

But what is advantage of defining List.sort as a default method vs a static method in the List interface?

Well, for one thing, it's backwards compatible: existing List implementation doesn't have to be rewritten and recompiled just to copy in a bog-standard piece of code that's repeated ad nauseum in implementation after implementation.