2 ms·
final List<?> immutable = Collections.immutableList(x)... and pass it around. Never expose your collections directly (unless you are willing to go copy on wri
by xxs 8y ago
final List<?> immutable = Collections.immutableList(x)...
and pass it around.
Never expose your collections directly (unless you are willing to go copy on write and immutable objects inside the collections, the latter is very welcome, though)
- stickfigure 8y agoAlso, if you want to go 'whole hog' you can use any of the functional/immutable collection libraries like vavr, functionaljava, or jimmutable.