Hacker News new | ask | show | jobs
by ncmncm 1653 days ago
Inheritance is flawed, in Java, mainly because it is the only organizing principle offered, so gets shoehorned into all kinds of problems where it is a poor fit.

Inheritance is just the right thing once in a while, but Java coders are obliged to apply it well beyond its useful range.

2 comments

Just because it exists doesn’t mean it has to be used beyond its intended domain. One is entirely free to create flat “hierarchies” in Java. But I agree that in hindsight, final classes as a default would be better.

Fortunately nowadays, records and sealed classes remedy this for the most part in java.

What do you mean by "obliged to apply it"? For example, I very very rarely apply it and nobody is forcing me to create inheritance hierarchy.