On Tue, 11 Aug 2026 19:04:11 GMT, Chen Liang <[email protected]> wrote:

>> The 3 methods to determine conversions and subtyping on `java.lang.Class`, 
>> which are `isInstance`, `cast`, and `isAssignableFrom`, have their 
>> documentation from the earliest days of the Java Platform. During the 
>> language evolution, a lot of terms have become inaccurate, such as 
>> "assignment-compatible", which does not apply for primitive types, and the 
>> out-of-date instanceof analogy with the upcoming patterns, in `isInstance`; 
>> `isAssignableFrom` is not very clear about arrays; `cast` would also benefit 
>> from more detailed explanations.
>> 
>> In my facelift, I moved the subtyping description to `isAssignableFrom`, and 
>> left the conversion stuff in `isInstance` and `cast`.  I intentionally 
>> avoided linking to too many JLS chapters to reduce confusions. I believe in 
>> this shape, we have a good amount of easily comprehensible yet accurate 
>> specification for all 3 methods, and users are welcome to read the linked 
>> JLS chapters for more details and context.
>> 
>> ---------
>> - [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 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 15 additional commits since 
> the last revision:
> 
>  - Bug spotted by Aggelos
>  - Merge branch 'master' of https://github.com/openjdk/jdk into 
> doc/class-casts
>  - Typo tweaks
>  - Merge branch 'master' of https://github.com/openjdk/jdk into 
> doc/class-casts
>  - Rendering updates
>  - More tweaks
>  - Merge branch 'master' of https://github.com/openjdk/jdk into 
> doc/class-casts
>  - Tweak
>  - Merge branch 'master' of https://github.com/openjdk/jdk into 
> doc/class-casts
>  - Stage
>  - ... and 5 more: https://git.openjdk.org/jdk/compare/0aa8659c...725cedfc

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

> 819:      *     (1) T is the same as P; (2) T is a superclass of P; (3) T is a
> 820:      *     superinterface of P; or (4) T is the {@link Object} class, 
> and P is
> 821:      *     a reference type.

To make the cases non-overlapping: "T is the {@link Object} class, and P is an 
interface or array type"

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

PR Review Comment: https://git.openjdk.org/jdk/pull/28684#discussion_r3761070847

Reply via email to