It is known that there is a
java.util.Collections class that has methods of the
unmodifiable* type that return immutable collections. Now the question is how to determine that a collection is immutable?
You will hardly find any universal good solution.
In my opinion, the least crutch is
List<String> list = new ArrayList<>(); List<String> unmodifiableList = Collections.unmodifiableList(list); boolean isUnmodifiable = Collections.unmodifiableList(list).getClass().isInstance(unmodifiableList);
UnsupportedOperationExceptionwhen adding an element. But then, in the case of a mutable collection, the element must be removed after the test.