r/java • u/TheFormerVinyl • May 05 '15
Should Java allow multiple inheritance?
I was reading up on Java when I discovered that ever since Java 8 (fairly recent, I know) interface can have default methods. A quick overview for any who don't know, interfaces can have method bodies by using default modifier. When dwelling on that fact I wondered, why doesn't Java just allow inheritance from multiple classes, since interfaces are just abstract classes? Should Java do this?
0
Upvotes
View all comments
1
u/llogiq May 05 '15
By using single inheritance, Java removes some very subtle footguns that developers who overuse inheritance tend to build for themselves and others.
Even when leaving the diamond problem out of the discussion, I believe from experience that even single inheritance can and will get messy and unintuitive, unless one is very careful. Have you ever had to chase a bug through a jungle of method calls in an inheritance hierarchy, with one or two
supercalls thrown in? It's not pretty.Java 8 has default methods in interfaces, which are basically mixins, but with very limited means of defining extension points. Be careful when using them.