Indexing access for Lists and Maps considered harmful?

Artur Biesiadowski abies at adres.pl
Tue Jun 23 11:02:37 PDT 2009


Joseph D. Darcy wrote:
> // 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);
> }
>   
If anything like that is implemented, I would rather see it as two 
interfaces - ListAccess and MapAccess (or maybe IndexAccess and 
Key/DictionaryAccess to be less collection-oriented?). Read-only or 
write-only classes can throw runtime exceptions if needed.

Do you think that one-operation classes would be common? I can see a 
possible benefit of detecting this at compile time instead of runtime, 
but how useful it would be in real world...

All collection classes would be read-write (even for immutable 
collections no way to indicate it on interface level).
String could be probably made 'GettableFromInt'.
StringBuilder/Buffer is already read-write. Same goes for BitSet.

I think it boils down to question if we want to have

String txt = "ABC";
txt[0] = 'X';

failing at compile time or runtime. On the other hand, in case of 
String, I could imagine most IDEs making it a warning at compile time 
easily...

Regards,
Artur Biesiadowski



More information about the coin-dev mailing list