| Author |
Collection optional operation
|
Jonas Dimsa
Greenhorn
Joined: Apr 02, 2007
Posts: 9
|
|
hi, does "optional operation" in interface(etc remove(Object o) in Collection) mean that implementing class has not necessarily to implement that method? if yes, how to create such interface. thanks
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
It means the implementation can just throw an UnsupportedOperationException instead of doing any actual work. The collections returned by Collections.unmodifiableXXX all throw this exception when trying to add, remove or set anything.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
bart zagers
Ranch Hand
Joined: Feb 05, 2003
Posts: 234
|
|
When you want to implement your own Collection, it is often convenient to start from one of the available AbstractX classes. For example AbstractList. This will give you a default implementation for all the methods you don't have to implement (for example throw an UnsupportedOperationException in the case you don't implement the remove method).
|
 |
 |
|
|
subject: Collection optional operation
|
|
|