Proposal: Indexing access syntax for Lists and Maps
Mark Thornton
mthornton at optrak.co.uk
Mon Mar 30 06:51:06 PDT 2009
Shams Mahmood wrote:
> Hi Joe,
>
> Haven't used too many annotations in Java code. I had fiddled with the idea
> of Indexable (yes even I
> had come up with the same name - our vocabularies are so limited ;) ), but I
> decided otherwise for the
> following reasons:
>
> 1) Java traditionally has wanted to avoid operator overloading (Indexable
> means compiler providing
> operator support for Indexable marked classes). Although for each loops have
> special handling cases
> for Iterable types.
> 2) get/set implementation of Lists and Maps will need to change. In fact Map
> doesn't even have a
> set, so a new method will be added to the interface breaking backwards
> compatibility.
>
> Shams.
>
>
The advantage of using an annotation is that the List/Map interfaces
DON'T need to change other than the addition of the annotation to
specify the methods to be used for indexed get and set. So Map becomes
something like:
interface Map<K,V> {
@indexedGet V get(Object key);
@indexedSet V put(K key, V value);
// rest unchanged
}
interface List<E> {
@indexedGet E get(int index);
@indexedSet E set(int index, e element);
}
Implementations of these interfaces don't need to change at all. A
marker interface could be used as well, but doesn't seem to me to be
strictly necessary (I'll post some more suggestions on this later).
Regards,
Mark Thornton
More information about the coin-dev
mailing list