Code review request for 4881419 The type of X[].clone() should be X[]

Joe Darcy joe.darcy at oracle.com
Fri Sep 3 22:00:59 UTC 2010


Martin Buchholz wrote:
>
>
> On Thu, Sep 2, 2010 at 17:50, Joe Darcy <joe.darcy at oracle.com 
> <mailto:joe.darcy at oracle.com>> wrote:
>
>     Martin Buchholz wrote:
>
>         The usage T[] suggests that T is a reference type, as with
>         generics, which is not the case here.
>
>         More precisely, both the runtime types and compiletime types
>         of the object returned from clone of any array is identical to
>         its input.
>         Is there a non-confusing way of saying that?
>
>
>     How about
>
>     "...and that the return type of the {@code clone} method of an
>     array type {@code T[]} is {@code T[]} where T is either a
>     reference or a primitive type."?
>
>
> So I went and actually read the Object.clone spec, and it does indeed 
> guarantee that the (runtime) class of the returned value is the same 
> as the class of the argument, for arrays.  As for the compile-time 
> type, an experiment demonstrates that the return type is indeed 
> exactly the same, including for non-reifiable array element types, 
> e.g. this compiles:
>
>         Class<? extends Number>[] a
>             = (Class<? extends Number>[]) (new Class<?>[42]);
>         Class<? extends Number>[] clone = a.clone();
>
>
> So Ulf's restriction to non-reifiable T seems not to be correct.
>
> My suggested wording is:
>
> "...and that the return type of the {@code clone} method of an array 
> type {@code T[]} is {@code T[]} where T is any reference or primitive 
> type."
>
> Martin "Objects have class; Variables have type"

Sounds good to me; change pushed!

Thanks,

-Joe




More information about the core-libs-dev mailing list