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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
dimitrilc
Posts: 34
Joined: Sat Jun 06, 2020 4:51 pm
Contact:

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

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

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Yes, that is correct. (The statement should say UnsupportOperationException instead of OperationNotSupportedException though). Fixed.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests