Tuesday, May 11, 2010

I'm hacking some Java code and I'm going to do a query and return some objects. Since I have no need to mutate the collection, I decide to use an immutable list. To make a long story short, I did this:

It turns out that the query method wants to mutate the collection. (This is obnoxious. When I borrow something I try to leave it in the same condition as when I got it. I don't go mutating it and I expect my libraries to extend the same courtesy.) I guess I don't care all that much — I can simply make the collection mutable.

So why can't I just delete the `Immutable' prefix?

// Now it is named `Lists' with an `s'
import com.foo.bar.Lists;
// Now I have to specify the implementation technique.
// Why isn't it a List.builder?
final List<Object> intermediateCollection = Lists.newArrayList();
// Why isn't there build that is a no-op?
query (intermediateCollection)