Indexing access for Lists and Maps considered harmful?

Joseph D. Darcy Joe.Darcy at Sun.COM
Tue Jun 23 10:36:09 PDT 2009


spamolovko wrote:

[snip]
>
> PS i remember that coin project had discussion about usage of special 
> interface for "indexing access". That interface have to use it's own 
> methods for access to data, so no problems with get semantic.
>
> Example:
>
> public interface Indexer<KeyType, ValueType> {
>
>     public ValueType indexGet(KeyType key);
>
>     public void indexSet(KeyType key, ValueType value);
>
> }
>   

[snip]

The idea would be to retrofit new superinterfaces onto the List and Map 
interfaces without adding new methods to the interfaces. For example, 
here is a slight refinement of strawman interfaces of that sort from my 
JavaOne talk:

// New superinterfaces to indicate syntax?
interface GettableFromInt<E> {
E get(int);
}

interface Gettable<K, V> {
V get(K k);
}

interface Settable<E> {
E set(int, E e);
}
interface Puttable<K, V> {
V put(K k, V v);
}

java.util.List<E> extends GettableFromInt<E>, Settable<E>, …

java.util.Map<K, V> extends Gettable<Object, V>, Puttable(K, V), …

The names "Gettable" etc. are open to improvement :-)

-Joe



More information about the coin-dev mailing list