r/java • • Mar 16 '21

Java 16 / JDK 16: General Availability

196 Upvotes

82 comments sorted by

View all comments

Show parent comments

4

u/kag0 Mar 16 '21

True, maybe I should have suggested they create a ReadOnlyCollection (which would be useful other places where add throws UnsupportedOperationException).
Or hell, just have it return Iterable.

Anyway, I don't mean to suggest I have the answer. Just that this is probably the last option I would have picked.

-2

u/elastic_psychiatrist Mar 16 '21

Anyway, I don’t mean to suggest I have the answer. Just that this is probably the last option I would have picked.

Spoken by many a backseat language designer, who has not fully grasped the problem and the implications of potential solutions.

-5

u/BlueGoliath Mar 16 '21

Oh shut up.

JavaFX provides a ReadOnlyObjectProperty which are then extended by ObjectProperty and it works perfectly fine. This isn't some radical, untested idea.

The List and collection APIs are poorly designed even beyond not providing a read only base. Why the hell would a list of generic type Cat contain a type of Dog?

-1

u/elastic_psychiatrist Mar 17 '21

Being a steward of the Java ecosystem is not as simple as throwing away imperfect APIs.

Perhaps you could build a language with only perfect APIs. I would use it!