3 ms·
Meh. What's next? Multiple inheritance?! I'm gonna need a better hypothetical than FilteredSet<E> to assess any benefits. Today, people use factory methods to
by specialist 4y ago
Meh.
What's next? Multiple inheritance?!
I'm gonna need a better hypothetical than FilteredSet<E> to assess any benefits. Today, people use factory methods to achieve that result.
Or just use a compound statement. Something like (pseudo-codimously):
class FilteredSet <E> {
public FilteredSet( Predicate<? super E> pred, Collection<? extends E> elems ) {
super( elems.apply( pred ));
this.pred = pred;
}
}
My hunch (believe but cannot prove) is that Java's current constraint serves to encourage composition over inheritance. Which is The Correct Answer™.
My limited anecdata wrt Java's "constructors must invoke super()/this() first" is this complaint arises when porting from C++ to Java. Because the original class hierarchy leans heavily on inheritance for organizing behaviors.