jdk-24/test/langtools/tools/javac/patterns/PrimitiveInstanceOfErrors.java
Aggelos Biboudis 1733d2ea24 8303374: Implement JEP 455: Primitive Types in Patterns, instanceof, and switch (Preview)
Co-authored-by: Jan Lahoda <jlahoda@openjdk.org>
Co-authored-by: Maurizio Cimadamore <mcimadamore@openjdk.org>
Co-authored-by: Gavin Bierman <gbierman@openjdk.org>
Co-authored-by: Brian Goetz <briangoetz@openjdk.org>
Co-authored-by: Raffaello Giulietti <rgiulietti@openjdk.org>
Co-authored-by: Aggelos Biboudis <abimpoudis@openjdk.org>
Reviewed-by: vromero, jlahoda
2024-01-31 14:18:13 +00:00

28 lines
1.1 KiB
Java

/*
* @test /nodynamiccopyright/
* @bug 8304487
* @summary Compiler Implementation for Primitive types in patterns, instanceof, and switch (Preview)
* @enablePreview
* @compile/fail/ref=PrimitiveInstanceOfErrors.out -XDrawDiagnostics -XDshould-stop.at=FLOW PrimitiveInstanceOfErrors.java
*/
public class PrimitiveInstanceOfErrors {
public static boolean unboxingAndNarrowingPrimitiveNotAllowedPerCastingConversion() {
Long l_within_int_range = 42L;
Long l_outside_int_range = 999999999999999999L;
return l_within_int_range instanceof int && !(l_outside_int_range instanceof int);
}
public static <T extends Integer> boolean wideningReferenceConversionUnboxingAndNarrowingPrimitive(T i) {
return i instanceof byte;
}
public static void boxingConversionsBetweenIncompatibleTypes() {
int i = 42;
boolean ret1 = i instanceof Integer; // (Integer) i // OK and true
boolean ret2 = i instanceof Double; // error: incompatible types
boolean ret3 = i instanceof Short; // error: incompatible types
}
}