On Fri, 31 Jul 2026 04:28:36 GMT, Chen Liang <[email protected]> wrote:

>> Introduce an instance method, `isClassOrInterface`, to `java.lang.Class` and 
>> `java.lang.invoke.TypeDescriptor$OfField`.
>> 
>> `java.lang.constant.ClassDesc` comes with an `isClassOrInterface` method. It 
>> turns out that such a check is frequently needed in the use of `Class` 
>> objects, usually as `isArray() || isPrimitive()` or `!isArray() && 
>> !isPrimitive()`, with 14 occurrences in various reflective code.
>> 
>> In addition, `Class` can offer a more efficient implementation than two 
>> checks: it can perform a single bit pattern check to derive this result, 
>> making such an API more feasible.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Chen Liang has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Wording review from Joe

src/java.base/share/classes/java/lang/Class.java line 912:

> 910:      * #isHidden() hidden classes}, {@linkplain #getEnclosingClass() 
> enclosing
> 911:      * classes}, {@linkplain #getNestMembers() nest members}, only apply 
> to
> 912:      * classes and interfaces.

The first sentence of the method description is good. 

I'm less sure about the rest of the paragraph, esp.  the term "reflective 
concepts" as it appears out of thin air. Is this really needed? I don't see a 
need to say anything about hidden classes here (Joe's comment is addressed by 
having "class or interface" in the Hidden Classes section link to the method).  
The method could say that it returns false for primitive and array classes as 
that is a question that potential users of this API will wonder about.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/32109#discussion_r3690058275

Reply via email to