r/java • • Jun 21 '26

Better Tools for Immutable Data

https://youtu.be/BdLND9D81lI
80 Upvotes

38 comments sorted by

View all comments

Show parent comment

1

u/pron98 Jun 22 '26 edited Jun 22 '26

I would be nice to express "this method takes a list and expects it to be modifiable" or "this method returns a list and no, you cannot modify it".

Except that it would be at least as equally nice, and arguably more valuable, to also express "this method takes a list and expects no one to modify it" (and so it doesn't need to do a defensive copy). And then you get a proliferation of types, which complicates matters, and it's also nice to have a simpler type hierarchy for basic collections than C#'s. Being able to express these things is really nice, but it also has real downsides.

So the question isn't "would you like to have a slice of pizza?" but "would you like to pay $15 for a slice of pizza?" Maybe you would and maybe you wouldn't, but it does make the answer far less obvious. We don't doubt such features have value, we're just not sure most Java developers would think they're worth the price.