Right now ImmutableList will give the standard AbstractList's subList. While not terrible, it certainly could be much better. In particular, it would be nice to have
ImmutableList.subList().subList() not create a nested list that has to go through 2 indirections but could directly access the contents of the root one (this is safe because we never have to worry about shifting boundaries from additions because ImmutableList is, well, imuutable.
It would override subList to return ImmutableList, making it very obvious to the user that the returned subList is also immutable.
The former wouldn't be too hard, the latter however may require some extra work. Right now, the assumption that the whole array of ImmutableList is the entire list contents, no slack. However, for a subList, we would want a view of a subset of the array. That would require overriding quite a few methods if it were to extend from ImmutableList, as the assumption that the whole array is the contents no longer holds.
Possibly, we can just document in the Javadoc that the returned subList is immutable, but not actually extend from it, and maybe put a note that in the future it may be declared an ImmutableList (and thus you shouldn't rely on the return type if you do extend this class)
Right now ImmutableList will give the standard AbstractList's subList. While not terrible, it certainly could be much better. In particular, it would be nice to have
ImmutableList.subList().subList()
not create a nested list that has to go through 2 indirections but could directly access the contents of the root one (this is safe because we never have to worry about shifting boundaries from additions becauseImmutableList
is, well, imuutable.subList
to returnImmutableList
, making it very obvious to the user that the returned subList is also immutable.The former wouldn't be too hard, the latter however may require some extra work. Right now, the assumption that the whole array of
ImmutableList
is the entire list contents, no slack. However, for asubList
, we would want a view of a subset of the array. That would require overriding quite a few methods if it were to extend fromImmutableList
, as the assumption that the whole array is the contents no longer holds.Possibly, we can just document in the Javadoc that the returned
subList
is immutable, but not actually extend from it, and maybe put a note that in the future it may be declared anImmutableList
(and thus you shouldn't rely on the return type if you do extend this class)