RFR: 8310242: Clarify the name parameter to Class::forName [v6]
Mandy Chung
mchung at openjdk.org
Thu Jun 22 02:06:11 UTC 2023
On Wed, 21 Jun 2023 23:06:23 GMT, Chen Liang <liach at openjdk.org> wrote:
>> Mandy Chung has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains eight additional commits since the last revision:
>>
>> - improve the specification of forName
>> - Merge branch 'master' of https://github.com/openjdk/jdk into JDK-8310242
>> - Merge branch 'master' of https://github.com/openjdk/jdk into JDK-8310242
>> - Review comment. Add a test
>> - missing 'L' for the array class name
>> - review comment
>> - Clarify for an array class of primitive type
>> - 8310242: Clarify the name parameter to Class::forName
>
> src/java.base/share/classes/java/lang/Class.java line 438:
>
>> 436: * representing primitive types or void, hidden classes or interfaces,
>> 437: * or array classes whose element type is a hidden class or interface.
>> 438: * If {@code name} denotes a primitive type or void, for example {@code I},
>
> I think `{@code int}` would be a better example here as Java programmers aren't in touch with bytecode descriptors mostly.
One main point for this example to show is that it will find a class in unnamed package named `I` - a class named `I` is not uncommon but it's unlikely to have a class named `int`.
> src/java.base/share/classes/java/lang/Class.java line 459:
>
>> 457: * from {@code forName(}<i>N</i>{@code )} returns <i>N</i>.
>> 458: *
>> 459: * <p> A call to {@code forName("[L}<i>N</i>{@code ;")} causes the element type
>
> This appears true for multi-dimensional arrays as well, but the name format here only applies to single-dimension arrays.
I considered that. The spec and the example already describe multi-dimensional array. I think one can infer from this single-dimensional array example.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/14528#discussion_r1237904930
PR Review Comment: https://git.openjdk.org/jdk/pull/14528#discussion_r1237906383
More information about the core-libs-dev
mailing list