aspose file tools*
The moose likes Java in General and the fly likes Collection optional operation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Collection optional operation" Watch "Collection optional operation" New topic
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: 19720
    
  20

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 - OCEEJBD 6
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).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Collection optional operation