RFR: 5047859 : (reflect) Class.getField can't find String[].length

Mandy Chung mandy.chung at oracle.com
Thu Aug 29 01:54:25 UTC 2013


On 8/28/2013 6:39 AM, Joel Borggrén-Franck wrote:
> Hi Mandy,
>
> Thanks for your comments,
>
> On 2013-08-26, Mandy Chung wrote:
>> Joel,
>>
>> The spec of the getFields and getDeclaredFields() methods both states this:
>>
>>    This method returns an array of length 0 if the class
>>    or interface declares no fields, or if this|Class|  object
>>    represents a primitive type, an array class, or void.
>>
>> The spec of the getDeclaredField() method has this sentence:
>>
>>    Note that this method will not reflect the {@code length}
>>    field of an array class.
>>
>> Your change is okay and it would be good to keep the getField(s)
>> and getDeclaredField(s) methods be consistent and states its
>> return value "if this|Class|  object represents a primitive type,
>> an array class, or void"
> I agree the javadoc for the 4 methods should be more uniform. The note
> in getDeclaredFields() isn't that good IMHO as for example the term
> 'array class' in not used in JLS.
>
> I'll be back shortly with an updated webrev.
>

You may also want to check out getConstructor(s) and 
getDeclaredConstructor(s) that seem to have similar inconsistency issue.

Mandy



More information about the core-libs-dev mailing list