Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
String[] , Arrays.asList , Collections.unmodifiableList
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Roedy Green, post: 5158704"] I wrote a method of the form String[] someMethod( ... ) IntelliJ complained this was a wicked thing todo. Why? Because the caller could modify the String array it at would wreck by copy inside SomeMethod. So what do people do? They use Arrays.asList to convert to a List, an java.util.Arrays$ArrayList. But List still lets the user modify the field which in turn modify the underlying array. We have gained nothing. We have to use Collections.unmodifiableList which gives us a Collections.unmodifiableList wrapper around our List that throws UnsupportedOperationException when we attempt to write. The catch is the set methods are still there. We don't find out about the problem of modifying this list until run time. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
String[] , Arrays.asList , Collections.unmodifiableList
Top