Type, record and primitive patterns, guards, sealed exhaustiveness, MatchException via separate compilation, and eight captured transcripts. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TF9JWFvJSNm6HVzswzZU5a
17 lines
807 B
Java
17 lines
807 B
Java
public class PrimitiveEdges {
|
|
public static void main(String[] args) {
|
|
double[] ds = {0.0, -0.0, Double.NaN, 16777217.0, 1e10, 3.0};
|
|
for (double d : ds) {
|
|
System.out.printf("%-12s int? %-5b float? %-5b%n", d, d instanceof int, d instanceof float);
|
|
}
|
|
long big = 1L << 40;
|
|
System.out.println(big + " instanceof int? " + (big instanceof int));
|
|
Object o = 42;
|
|
if (o instanceof int i) System.out.println("Object holding Integer matches int pattern: " + i);
|
|
Object s = (short) 7;
|
|
if (s instanceof int i) System.out.println("Short in Object matches int? " + i); else System.out.println("Short in Object does not match int");
|
|
int x = 65;
|
|
if (x instanceof char c) System.out.println("65 as char: " + c);
|
|
}
|
|
}
|