Am 03.09.2010 08:22, schrieb Martin Buchholz:


On Thu, Sep 2, 2010 at 17:50, Joe Darcy <joe.da...@oracle.com 
<mailto:joe.da...@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.

Oops, my English :-(
I interpreted your term "...as with generics, which is not the case here." as 
such reification.


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"

I think the question of variable types belongs to the spec, but here in Object class's javadoc we should speak about objects. So I now suggest: "...and that the returned object of the {...@code clone} method of an array object of class {...@code T[]} is of class {...@code T[]} where T is any [raw]? reference or primitive class. See java language specification version 3, section 6.4.5"

-Ulf

Reply via email to