Preincrement of array element

Boehm, Hans hans_boehm@hp.com
Wed Sep 26 19:12:00 GMT 2001


A silly observation/question:

In Java are the semantics of ++a[i] always exactly the same as a[i]+= 1?

The latter already did the right thing.

I just hacked the parser to (I hope!) generate the same tree for ++a[i] that
it previously already generated for a[i] += 1.  This is about a 3 line patch
(6 if you also handle predecrement) and superficially appears to fix the
problem.  And it doesn't immediately break anything I tried.  According to
the C standard, these are equivlent.  The Java spec is more complicated in
this regard due to exceptions, string +=, etc., but I didn't immediately see
a difference.

Hans



More information about the Java mailing list