On Wed, 25 Jun 2025 19:57:56 GMT, Xueming Shen <sher...@openjdk.org> wrote:

>> Fixed in 
>> [d5abfa4](https://github.com/openjdk/jdk/pull/25863/commits/d5abfa450cb3fcd604560833038735e41952bce9
>> ).
>
> My apologies if this is a naive question :-) I'm sure this was discussed when 
> the method was added, so this is just for my own education.
> 
> What's the benefit of explicitly specifying that the returned list is 
> unmodifiable here? For example, Files.readAllLines() says that whether the 
> list is modifiable is implementation-dependent and not specified.
> 
> In this case, it seems the returned list is a final result — a snapshot — and 
> there's no real harm (to the reader) even if the caller modifies it. So is 
> marking it unmodifiable more of a design philosophy? Or do we have data (or 
> experience) suggesting that most usage scenarios prefer an unmodifiable 
> collection?

A design philosophy, generally toward immutability to make data structures more 
predictable and safer from action at a distance complications.
It avoids ambiguity that some using the API might assume or depend on if not 
specified.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25863#discussion_r2167586376

Reply via email to