News for hackers. Stuff that matters.
Re:Java 7 - What's new? Release date, code examples and perf... by _delirium on Monday April 12, 2010 @01:11AM (#1258461)
The List interface labels all the methods that could change a list as "optional operation", which implementing classes are free to throw an UnsupportedOperationException for: http://java.sun.com/javase/6/docs/api/java/util/List.html

The current API already uses this in a bunch of places to return immutable Lists. For example, the lists you get out of Collections.singletonList() or Collections.nCopies() are immutable.

That's a bit broken from an OO perspective (is the interface an interface or not?), but it's a better solution than the const v. non-const container mess that C++/STL has, at least.

There are no comments on this comment yet.