Indexing access for Lists and Maps considered harmful?

Rémi Forax forax at univ-mlv.fr
Wed Jun 24 04:04:54 PDT 2009


Ted Neward a écrit :
> This is true regardless of the map/list syntax, though, isn't it?
>   

Yes, the compiler first try to find a method without boxing and then 
with boxing
and with generics and boxing.
This was necessary to be backward compatible with 
pre-boxing/pre-generics code.

> public class BoxingPuzzler
> {
>   public static void doSomething(int i) { System.out.println("int"); }
>   public static void doSomething(Integer i) { System.out.println("Integer");
> }
>   public static void doSomething(Object o) { System.out.println("Object"); }
>
>   public static void main(String[] args)
>   {
>     Object o = null;
>
>     doSomething(o = 5);
>   }
> }
>
> This prints "Object" at the command-line. (Interestingly, after a few
> seconds of experimentation, I can't get it to invoke the Integer version,
> but it definitely doesn't invoke the "int" version. Not having the Object
> version yields a compile error. Brighter minds than mine can probably get
> Integer to be invoked.)
>   

You can't.

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

Rémi



More information about the coin-dev mailing list