Collection.toArray(IntFunction)
Peter Levart
peter.levart at gmail.com
Fri May 31 03:15:41 PDT 2013
On 05/30/2013 06:16 PM, Martin Buchholz wrote:
> Cleaning up all of those unclear "runtime type" specs in the libraries and
> jls can be a bit of work.
> Probably could link to
> http://docs.oracle.com/javase/specs/jls/se7/html/jls-10.html#jls-10.5 and
> use the terminology from there
>
> """
> If the type of the value being assigned is not assignment-compatible (§5.2)
> with the component type, an ArrayStoreException is thrown.
> """
>
> but there will always be confusion about "compile-time type" and "runtime
> type".
>
> """Variables have type; objects have class"""
Hi,
While JLS wording is correct and can be used for the toArray() javadoc,
I think it is more general than required for the concrete situation. The
JLS paragraph talks about assignment-compatibility, which includes
subtyping, but in toArray only the subtyping matters, since both the
array component type and the runtime type of Collection element are
reference types.
To disambiguate the compile-time type from run-time types, perhaps the
wording could include "runtime" also on the array side:
@throws ArrayStoreException if the *runtime component* type of the specified array is not a supertype of the runtime type of every element in this collection
Regards, Peter
>
> On Thu, May 30, 2013 at 1:34 AM, Paul Sandoz <paul.sandoz at oracle.com> wrote:
>
>>
>>> I also noticed an error in the javadoc of the other
>>> Collection.toArray(T[]) method (line 240). Instead of the following:
>>>
>>> * @throws ArrayStoreException if the *runtime*type of the
>>> specified array
>>> * is not a supertype of the runtime type of every element in
>>> * this collection
>>>
>>> I think it should be:
>>>
>>> * @throws ArrayStoreException if the *component*type of the
>>> specified array
>>> * is not a supertype of the runtime type of every element in
>>> * this collection
>>>
>>>
>> Bug logged.
>>
>> Thanks,
>> Paul.
>>
>>
More information about the lambda-dev
mailing list