Primitives in Generics proposal.
reinier at zwitserloot.com
Wed Mar 10 06:29:39 PST 2010
Excellent point, Arthur. Let's presume for now that if int <-> Integer
conversion is required, an error is generated, until someone pulls a rabbit
out of a hat. Not much is lost here; even with the (as Arthur pointed out
too unwieldy) notion of converting arrays, List<int>.toArray(new int)
was already ridiculously inefficient with all the conversion going on.
toArray will remain to fill an object array with boxed Integer objects, and
a special method would exist to turn List<int> into int.
Technically a VM change can allow any attempt to write into an array of
component type I, if an array is actually given that is an object array, to
let the VM do the boxing, and vice versa, but that's quite a step to take
2010/3/10 <abies at adres.pl>
> "Reinier Zwitserloot" <reinier at zwitserloot.com> napisał(a):
> > I'll rebut point by point;
> > 1: int <-> Integer conversion doesn't preserve reference identity.
> > This rule has been broken before. In java 1.5, this assert isn't true,
> > because reference identity isn't maintained when boxing is applied:
> > Integer x = new Integer(10000000);
> > int y = x;
> > Integer z = x;
> > assert z == x; //This will fail!
> There is a big difference - Integer is immutable. Array is inherently
> mutable and if you add it to some generic container and then mutate contents
> of that array through outside reference, internal copy will not be changed.
> Artur Biesiadowski
More information about the lambda-dev