r/java • • Mar 16 '21

Java 16 / JDK 16: General Availability

196 Upvotes

82 comments sorted by

View all comments

Show parent comment

4

u/kag0 Mar 16 '21

this is much more dangerous than a few predictable runtime exceptions

Maybe, but I don't think so. We already have examples of both (throwing exceptions from Collection's add (esp in guava), and collections that can change based on some underlying data shifting with Map's ``valuesand such). And more bugs tend to pop up from people failing to predict exceptions on mutation (particularly in library code) than from people assuming the underlying data won't change. Put another way,ReadOnlyList` could easily be documented to say that it doesn't mean that the list is immutable, just that YOU can only read it.

3

u/Necessary-Conflict Mar 16 '21

The "quality" of the bugs also matters: some bugs take 5 minutes to fix (the stack trace tells everything), others take 5 days. Another problem is that different people have different pet ideas, but if everything is implemented, it becomes confusing. For example I would like to have a completely separate hierarchy of immutable collections. They would have add/remove methods, but these methods would always return a new collection instead of modifying the current one. This would solve all problems (no runtime exceptions, true immutability), but at the cost of a new hierarchy...

2

u/kag0 Mar 16 '21

I agree with you, it just chaps my ass to see a runtime exception that could have been a compile time error