RFR: 8303374: Compiler Implementation for Primitive types in patterns, instanceof, and switch (Preview) [v3]
Maurizio Cimadamore
mcimadamore at openjdk.org
Tue Oct 3 15:00:36 UTC 2023
On Tue, 3 Oct 2023 13:19:18 GMT, Aggelos Biboudis <abimpoudis at openjdk.org> wrote:
>> src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java line 5052:
>>
>>> 5050:
>>> 5051: return (source.isPrimitive() && target.isPrimitive()) &&
>>> 5052: ((source.hasTag(BYTE) && !target.hasTag(CHAR) ||
>>
>> Does this mean that `byte` -> `char` is not exact? Aren't both integral types, thus invalidating `widening from one integral type to another` ?
>
> Indeed it is not unconditionally exact. byte to char combines both widening and narrowing primitive conversions
>
> https://docs.oracle.com/javase/specs/jls/se8/html/jls-5.html#jls-5.1.4
Ha! Of course - the problem is not the definition of "integral type" (which includes `char`), but the fact that there's no widening from `byte` to `char`. I agree that the code (and the spec changes) do the right thing.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/15638#discussion_r1344261063
More information about the core-libs-dev
mailing list