Indexing access for Lists and Maps considered harmful?

abies at adres.pl abies at adres.pl
Wed Jun 24 08:04:56 PDT 2009


 
"Reinier Zwitserloot" <reinier at zwitserloot.com> napisał(a): 
 > I am beginning to see some concensus on this list that the neal  
 > semantics are the most preferred semantics. That is:
 > 
 > FOO = (a[b] = c);
 > 
 > should be equal to:
 > 
 > a[b] = c;
 > FOO = a[b];
 > 
 > and thus, both a setter and a getter call.
 

I still don't understand why. It is not a case with current assignment operator.
public class Test {
volatile static int[] arr = new int[1];
volatile static int val = 0;
public static void main(String[] args) {
    int x,y;
    x = (val = 3);
    y = (arr[0] = 5);
}
}


compiles into

public static void main(java.lang.String[]);
  Code:
   0:   iconst_3
   1:   dup
   2:   putstatic       #2; //Field val:I
   5:   istore_1
   6:   getstatic       #3; //Field arr:[I
   9:   iconst_0
   10:  iconst_5
   11:  dup_x2
   12:  iastore
   13:  istore_2
   14:  return


Please note that there is no get from the arr nor from val, even if both are volatile and could be possible written into by another thread concurrently. 

x = (y = z)

IS NOT EQUAL TO

y = z;
x = y;

in current java.

It is equal to

tmp = z;
y = tmp;
x = tmp;

I don't understand why suddenly for sugar-on-top-of-collections we have to change the rules which are valid for normal values and arrays. There is no 'getter' equivalent called for anything in java currently, if you will modify jvm to catch retrieve-value-from-array, it will not be invoked, so why should getter be called on collections?

Regards,
Artur Biesiadowski



More information about the coin-dev mailing list