Indexing access for Lists and Maps considered harmful?

Bruce Chapman brucechapman at paradise.net.nz
Wed Jun 24 02:15:22 PDT 2009


Ted Neward wrote:
> In your implementation, indexSet *must* return ValueType, and it must return
> the value passed in, if the existing semantics for Java are going to be
> preserved. Am I missing something here? If, as I think Neal already pointed
> out, we look at the expression
>
> a = b = c;
>
> The results of the intermediate expression "b = c" is "c", and therefore the
> results of the expression "a = (b = c)" is "c" as well. What are we arguing
> about? This is established Java language semantics, isn't it?
>
>   
JLS 15.26 says
" The type of the assignment expression is the type of the variable 
after capture conversion "

and

"At run time, the result of the assignment expression is the value of 
the variable after the assignment has occurred."

To fully retain these semantics I think there should be a set/put for 
the first (right hand) assignment, then a get of that value (with same 
index) (unless it can be proven that the get will return the set/put 
argument) followed by the second set/put using the result of the get.

This then  nicely REQUIRES any return value from the set/put to be ignored!!

Note that given

    List<Integer> list;

then the type of the expression
   
    list[0] = 5

should have type Integer, not int.

Where the value of an assignment expression is used, a separate get 
invocation nicely does the right thing.

Bruce

> Ted Neward | Principal Consultant, ThoughtWorks
> Java, .NET, XML Services
> Consulting, Teaching, Speaking, Writing
> http://www.thoughtworks.com | http://www.tedneward.com
>
>   




More information about the coin-dev mailing list