News for hackers. Stuff that matters.
Re:Java 7 - What's new? Release date, code examples and perf... by mhansen on Monday April 12, 2010 @12:20AM (#1258393)
How does this maintain the List interface, which defines methods for mutating the collection through methods such as add() and remove()?

If I get a variable of type List, I expect to be able to change the list.

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.