Page 1 of 1
About Question enthuware.ocpjp.v8.2.1275 :
Posted: Fri Apr 07, 2017 5:02 am
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?
Re: About Question enthuware.ocpjp.v8.2.1275 :
Posted: Fri Apr 07, 2017 9:00 am
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.
Re: About Question enthuware.ocpjp.v8.2.1275 :
Posted: Fri Aug 03, 2018 12:46 pm
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.