1) You may have observed that the add(E e) and remove(int index) methods are mar
ID: 3781669 • Letter: 1
Question
1) You may have observed that the add(E e) and remove(int index) methods are marked as optional operations. Briefly discuss the benefits vs. pitfalls of this design decision.
2) Consider this quote from the java.util.List description:
Some list implementations have restrictions on the elements that they may contain. For example, some implementations prohibit null elements, and some have restrictions on the types of their elements.
Briefly discuss the benefits vs. pitfalls of this design decision.
http://web.cse.ohio-state.edu/software/2231/web-sw2/assignments/homeworks/java-util-list.html
Explanation / Answer
1)
add(E e) and remove( int index) are maeked as optional operations because these operations are
already written in ancestor classes so no need to declare once again. Benefit is "no need to declare
again" and pitfall is it will lead to some operations missing if we write in these functions.
-----------------------------------------------------------------------------------------------------
2)
Some list operations are having restrictions as they prohibit null implemens and they throw "NullPointerException".
Benefit is for some operations if we suddenly send any null values it simpley accepts and throw exception.
But pitfall is restrictions, user cannot use this all functions like size()...
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.