About Question enthuware.ocpjp.v8.2.1275 :

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

Moderator: admin

Post Reply
nikitos
Posts: 21
Joined: Mon Oct 24, 2016 6:55 am
Contact:

About Question enthuware.ocpjp.v8.2.1275 :

Post by nikitos »

Could you provide examples of UnsupportedOperationException?
I found by myself:

Code: Select all

List<Integer> list = Arrays.asList(1,2,3);
list.remove(0);
It is clear here that we actually link array to linkedlist...

What another possible way of generating UnsupportedOperationException?

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

Re: About Question enthuware.ocpjp.v8.2.1275 :

Post by admin »

You can simply have any class implement any interface and in the implementation method throw new UnsupportedOperationException. You will find several such examples in standard JDK classes. Just google throw new UnsupportedOperationException in jdk source code.

HTH,
Paul.

__JJ__
Posts: 125
Joined: Thu Jul 05, 2018 6:44 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1275 :

Post by __JJ__ »

Hi,
As it happens I was reading the Oracle Collections trail last night and retook a test with this question on just now, so I remembered that Oracle wrote something about this regarding the implementations, so just in case it comes up on the exam:
To keep the number of core collection interfaces manageable, the Java platform doesn't provide separate interfaces for each variant of each collection type. (Such variants might include immutable, fixed-size, and append-only.) Instead, the modification operations in each interface are designated optional — a given implementation may elect not to support all operations. If an unsupported operation is invoked, a collection throws an UnsupportedOperationException. Implementations are responsible for documenting which of the optional operations they support. All of the Java platform's general-purpose implementations support all of the optional operations.

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests