Indexing access for Lists and Maps considered harmful?
spamolovko
spamolovko at gmail.com
Tue Jun 23 23:50:10 PDT 2009
Reinier Zwitserloot wrote:
> I agree to the theory of your post, but, so what?
>
> Java is not going to be perfect unless java is willing to sacrifice
> backwards compatibility, which it isn't. So, perfection can't be the
> goal - because if it is, then no language change is ever going to make
> it in, and paradoxically, that really brings java no closer to
> perfection.
>
Yes, that is true. I hope that Oracle will "sacrifice backwards
compatibility" and implement features that are standard for other good
languages.
And being "non perfect" is not a reason to stop evolution.
> So - so what that it isn't perfect? Let's roll with where I think you
> are trying to go, and create 2 interfaces, where the SetIndex
> semantics are defined as requiring the implementing class to return
> the logical value - e.g. boxing a primitive when assigning it into a
> list, for example.
>
> But now we can't retrofit java.util.List without breaking thousands of
> List implementations out there, so the conclusion would have to be
> that you can not use a List itself; you must use either a specific
> type (such as ArrayList, retrofitted to implement SetIndex), or a
> newly created List2 interface that also implements SetIndex. In this
> scenario, I'm assuming the name of the method isn't set(), as that
> would conflict with java.util.List's set which has different semantics.
>
public interface IndexedAccess<ValueType> {
public ValueType indexGet(int key);
public void indexSet(int key, ValueType value);
}
interface Collection<E> extends Iterable<E>, IndexedAccess<E>
and then just use:
List<String> list = new ...
list[0] = "hello";
What is the problems here?
>
> --Reinier Zwitserloot
>
More information about the coin-dev
mailing list