talking about something like this?The List.of/Set.of methods return an unmodifiable List/Set. So, if you try to clear the List returned by List.of, an OperationNotSupportedException will indeed be thrown.
Code: Select all
//Will run fine
ArrayList<String> als = new ArrayList<>(List.of("a", "b", "c"));
als.clear();
//Throws java.lang.UnsupportedOperationException at runtime
List<String> als2 = List.of("a", "b", "c");
als2.clear();