Collection.toArray(IntFunction)

Paul Sandoz paul.sandoz at oracle.com
Fri May 31 03:23:41 PDT 2013


On May 31, 2013, at 12:15 PM, Peter Levart <peter.levart at gmail.com> wrote:

> 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
> 

That would be my preference too.

Paul.


More information about the lambda-dev mailing list