Page 1 of 1

About Question enthuware.ocpjp.i.v11.2.3105 :

Posted: Thu Jun 25, 2020 3:29 pm
by dimitrilc
Greetings, is this explanation,
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.
talking about something like this?

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();

Re: About Question enthuware.ocpjp.i.v11.2.3105 :

Posted: Fri Jun 26, 2020 1:44 am
by admin
Yes, that is correct. (The statement should say UnsupportOperationException instead of OperationNotSupportedException though). Fixed.