package dfa; public class SwitchPrimitivePatternApplicable { public static void main(String[] args) { testChar(); testByte(); testShort(); testInt(); testLong(); testFloat(); testDouble(); testCharObject(); testByteObject(); testShortObject(); testIntObject(); testLongObject(); testFloatObject(); testDoubleObject(); testNumberObject(); testObject(); } private static void testObject() { Number i = 0.0; switch (i) { case char d -> System.out.println("1"); //error default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case byte d -> System.out.println("1"); default -> System.out.println("1"); } switch (i) { case short d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case int d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case int d -> System.out.println("1"); } switch (i) { case long d -> System.out.println("1"); } switch (i) { case long d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case float d -> System.out.println("1"); } switch (i) { case float d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case double d -> System.out.println("1"); } switch (i) { case float d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case double d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case Character d -> System.out.println("1"); //error } switch (i) { case Byte d -> System.out.println("1"); default -> System.out.println("1"); } switch (i) { case Short d -> System.out.println("1"); } switch (i) { case Short d -> System.out.println("1"); default -> System.out.println("1"); } switch (i) { case Integer d -> System.out.println("1"); } switch (i) { case Integer d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case Long d -> System.out.println("1"); } switch (i) { case Long d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case Float d -> System.out.println("1"); } switch (i) { case Float d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case Double d -> System.out.println("1"); } switch (i) { case Double d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case Number d -> System.out.println("1"); } switch (i) { case Object d -> System.out.println("1"); } } private static void testNumberObject() { Number i = 0.0; switch (i) { case char d -> System.out.println("1");//error default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case byte d -> System.out.println("1"); default -> System.out.println("1"); } switch (i) { case short d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case int d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case int d -> System.out.println("1"); } switch (i) { case long d -> System.out.println("1"); } switch (i) { case long d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case float d -> System.out.println("1"); } switch (i) { case float d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case double d -> System.out.println("1"); } switch (i) { case float d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case double d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case Character d -> System.out.println("1");//error } switch (i) { case Byte d -> System.out.println("1"); default -> System.out.println("1"); } switch (i) { case Short d -> System.out.println("1"); } switch (i) { case Short d -> System.out.println("1"); default -> System.out.println("1"); } switch (i) { case Integer d -> System.out.println("1"); } switch (i) { case Integer d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case Long d -> System.out.println("1"); } switch (i) { case Long d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case Float d -> System.out.println("1"); } switch (i) { case Float d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case Double d -> System.out.println("1"); } switch (i) { case Double d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case Number d -> System.out.println("1"); } switch (i) { case Object d -> System.out.println("1"); } } private static void testDoubleObject() { Double i = 0.0; switch (i) { case char d -> System.out.println("1");//error default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case byte d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case short d -> System.out.println("1");//error default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case int d -> System.out.println("1");//error default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case int d -> System.out.println("1");//error } switch (i) { case long d -> System.out.println("1");//error } switch (i) { case long d -> System.out.println("1");//error default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case float d -> System.out.println("1");//error } switch (i) { case float d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case double d -> System.out.println("1"); } switch (i) { case float d -> System.out.println("1");//error default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case double d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case Character d -> System.out.println("1");//error } switch (i) { case Byte d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Short d -> System.out.println("1");//error } switch (i) { case Short d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Integer d -> System.out.println("1");//error } switch (i) { case Long d -> System.out.println("1");//error } switch (i) { case Float d -> System.out.println("1");//error } switch (i) { case Double d -> System.out.println("1"); } switch (i) { case Number d -> System.out.println("1"); } switch (i) { case Object d -> System.out.println("1"); } } private static void testFloatObject() { Float i = 0F; switch (i) { case char d -> System.out.println("1");//error default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case byte d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case short d -> System.out.println("1");//error default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case int d -> System.out.println("1");//error default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case int d -> System.out.println("1");//error } switch (i) { case long d -> System.out.println("1");//error } switch (i) { case long d -> System.out.println("1");//error default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case float d -> System.out.println("1"); } switch (i) { case double d -> System.out.println("1"); } switch (i) { case float d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case double d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case Character d -> System.out.println("1");//error } switch (i) { case Byte d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Short d -> System.out.println("1");//error } switch (i) { case Short d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Integer d -> System.out.println("1");//error } switch (i) { case Long d -> System.out.println("1");//error } switch (i) { case Float d -> System.out.println("1"); } switch (i) { case Double d -> System.out.println("1");//error } switch (i) { case Number d -> System.out.println("1"); } switch (i) { case Object d -> System.out.println("1"); } } private static void testLongObject() { Long i = 0L; switch (i) { case char d -> System.out.println("1");//error default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case byte d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case short d -> System.out.println("1");//error default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case int d -> System.out.println("1");//error default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case int d -> System.out.println("1");//error } switch (i) { case long d -> System.out.println("1"); } switch (i) { case float d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case float d -> System.out.println("1"); } switch (i) { case double d -> System.out.println("1"); } switch (i) { case float d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case double d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case Character d -> System.out.println("1");//error } switch (i) { case Byte d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Short d -> System.out.println("1");//error } switch (i) { case Short d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Integer d -> System.out.println("1");//error } switch (i) { case Long d -> System.out.println("1"); } switch (i) { case Float d -> System.out.println("1");//error } switch (i) { case Double d -> System.out.println("1");//error } switch (i) { case Number d -> System.out.println("1"); } switch (i) { case Object d -> System.out.println("1"); } } private static void testIntObject() { Integer i = 0; switch (i) { case char d -> System.out.println("1");//error default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case byte d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case short d -> System.out.println("1");//error default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case int d -> System.out.println("1"); } switch (i) { case long d -> System.out.println("1"); } switch (i) { case float d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case float d -> System.out.println("1"); } switch (i) { case double d -> System.out.println("1"); } switch (i) { case Character d -> System.out.println("1");//error } switch (i) { case Byte d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Short d -> System.out.println("1");//error } switch (i) { case Short d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Integer d -> System.out.println("1"); } switch (i) { case Long d -> System.out.println("1");//error } switch (i) { case Float d -> System.out.println("1");//error } switch (i) { case Double d -> System.out.println("1");//error } switch (i) { case Number d -> System.out.println("1"); } switch (i) { case Object d -> System.out.println("1"); } } private static void testShortObject() { Short i = 0; switch (i) { case char d -> System.out.println("1");//error default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case byte d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case short d -> System.out.println("1"); } switch (i) { case int d -> System.out.println("1"); } switch (i) { case long d -> System.out.println("1"); } switch (i) { case float d -> System.out.println("1"); } switch (i) { case double d -> System.out.println("1"); } switch (i) { case Character d -> System.out.println("1");//error } switch (i) { case Byte d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Short d -> System.out.println("1"); } switch (i) { case Short d -> System.out.println("1");//error default -> System.out.println("1");//error } switch (i) { case Integer d -> System.out.println("1");//error } switch (i) { case Long d -> System.out.println("1");//error } switch (i) { case Float d -> System.out.println("1");//error } switch (i) { case Double d -> System.out.println("1");//error } switch (i) { case Number d -> System.out.println("1"); } switch (i) { case Object d -> System.out.println("1"); } } private static void testCharObject() { Character i = 0; switch (i) { case char d -> System.out.println("1"); } switch (i) { case byte d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case short d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case int d -> System.out.println("1"); } switch (i) { case long d -> System.out.println("1"); } switch (i) { case float d -> System.out.println("1"); } switch (i) { case double d -> System.out.println("1"); } switch (i) { case Character d -> System.out.println("1"); } switch (i) { case Byte d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Short d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Integer d -> System.out.println("1");//error } switch (i) { case Long d -> System.out.println("1");//error } switch (i) { case Float d -> System.out.println("1");//error } switch (i) { case Double d -> System.out.println("1");//error } switch (i) { case Number d -> System.out.println("1");//error } switch (i) { case Object d -> System.out.println("1"); } } private static void testByteObject() { Byte i = 0; switch (i) { case char d -> System.out.println("1");//error default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case byte d -> System.out.println("1"); } switch (i) { case short d -> System.out.println("1"); } switch (i) { case int d -> System.out.println("1"); } switch (i) { case long d -> System.out.println("1"); } switch (i) { case float d -> System.out.println("1"); } switch (i) { case double d -> System.out.println("1"); } switch (i) { case Character d -> System.out.println("1");//error } switch (i) { case Byte d -> System.out.println("1"); } switch (i) { case Short d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Integer d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Long d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Float d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Double d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Number d -> System.out.println("1"); } switch (i) { case Object d -> System.out.println("1"); } } private static void testDouble() { double i = 0; switch (i) { case int i2 -> System.out.println("1"); case null, default -> System.out.println("1"); } switch (i) { case int i2 -> System.out.println("1"); case null -> System.out.println("1"); default -> System.out.println("1"); } switch (i) { case char d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case byte d -> System.out.println("1"); default -> System.out.println("1"); } switch (i) { case short d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case int d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case int d -> System.out.println("1"); } switch (i) { case long d -> System.out.println("1"); } switch (i) { case long d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case float d -> System.out.println("1"); } switch (i) { case float d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case double d -> System.out.println("1"); } switch (i) { case float d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case double d -> System.out.println("1");//error default -> throw new IllegalStateException("Unexpected value: " + i);//error } switch (i) { case Character d -> System.out.println("1");//error } switch (i) { case Byte d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Short d -> System.out.println("1");//error } switch (i) { case Short d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Integer d -> System.out.println("1");//error } switch (i) { case Long d -> System.out.println("1");//error } switch (i) { case Float d -> System.out.println("1");//error } switch (i) { case Double d -> System.out.println("1"); } switch (i) { case Number d -> System.out.println("1"); } switch (i) { case Object d -> System.out.println("1"); } } private static void testFloat() { float i = 0; switch (i) { case char d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case byte d -> System.out.println("1"); default -> System.out.println("1"); } switch (i) { case short d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case int d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case int d -> System.out.println("1"); } switch (i) { case long d -> System.out.println("1"); } switch (i) { case long d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case float d -> System.out.println("1"); } switch (i) { case double d -> System.out.println("1"); } switch (i) { case float d -> System.out.println("1");//error default -> throw new IllegalStateException("Unexpected value: " + i);//error } switch (i) { case double d -> System.out.println("1");//error default -> throw new IllegalStateException("Unexpected value: " + i);//error } switch (i) { case Character d -> System.out.println("1");//error } switch (i) { case Byte d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Short d -> System.out.println("1");//error } switch (i) { case Short d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Integer d -> System.out.println("1");//error } switch (i) { case Long d -> System.out.println("1");//error } switch (i) { case Float d -> System.out.println("1"); } switch (i) { case Double d -> System.out.println("1");//error } switch (i) { case Number d -> System.out.println("1"); } switch (i) { case Object d -> System.out.println("1"); } } private static void testLong() { long i = 0; switch (i) { case char d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case byte d -> System.out.println("1"); default -> System.out.println("1"); } switch (i) { case short d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case int d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case int d -> System.out.println("1"); } switch (i) { case long d -> System.out.println("1"); } switch (i) { case float d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case float d -> System.out.println("1"); } switch (i) { case double d -> System.out.println("1"); } switch (i) { case float d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case double d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case Character d -> System.out.println("1");//error } switch (i) { case Byte d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Short d -> System.out.println("1");//error } switch (i) { case Short d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Integer d -> System.out.println("1");//error } switch (i) { case Long d -> System.out.println("1"); } switch (i) { case Float d -> System.out.println("1");//error } switch (i) { case Double d -> System.out.println("1");//error } switch (i) { case Number d -> System.out.println("1"); } switch (i) { case Object d -> System.out.println("1"); } } private static void testInt() { int i = 0; switch (i) { case char d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case byte d -> System.out.println("1"); default -> System.out.println("1"); } switch (i) { case short d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case int d -> System.out.println("1"); } switch (i) { case long d -> System.out.println("1"); } switch (i) { case float d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case float d -> System.out.println("1"); } switch (i) { case double d -> System.out.println("1"); } switch (i) { case Character d -> System.out.println("1");//error } switch (i) { case Byte d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Short d -> System.out.println("1");//error } switch (i) { case Short d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Integer d -> System.out.println("1"); } switch (i) { case Long d -> System.out.println("1");//error } switch (i) { case Float d -> System.out.println("1");//error } switch (i) { case Double d -> System.out.println("1");//error } switch (i) { case Number d -> System.out.println("1"); } switch (i) { case Object d -> System.out.println("1"); } } private static void testShort() { short i = 0; switch (i) { case char d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case byte d -> System.out.println("1"); default -> System.out.println("1"); } switch (i) { case short d -> System.out.println("1"); } switch (i) { case int d -> System.out.println("1"); } switch (i) { case long d -> System.out.println("1"); } switch (i) { case float d -> System.out.println("1"); } switch (i) { case double d -> System.out.println("1"); } switch (i) { case Character d -> System.out.println("1");//error } switch (i) { case Byte d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Short d -> System.out.println("1"); } switch (i) { case Short d -> System.out.println("1");//error default -> System.out.println("1");//error } switch (i) { case Integer d -> System.out.println("1");//error } switch (i) { case Long d -> System.out.println("1");//error } switch (i) { case Float d -> System.out.println("1");//error } switch (i) { case Double d -> System.out.println("1");//error } switch (i) { case Number d -> System.out.println("1"); } switch (i) { case Object d -> System.out.println("1"); } } private static void testChar() { char i = 0; switch (i) { case char d -> System.out.println("1"); } switch (i) { case byte d -> System.out.println("1"); default -> System.out.println("1"); } switch (i) { case short d -> System.out.println("1"); default -> System.out.println("1"); } switch (i) { case int d -> System.out.println("1"); } switch (i) { case long d -> System.out.println("1"); } switch (i) { case float d -> System.out.println("1"); } switch (i) { case double d -> System.out.println("1"); } switch (i) { case Character d -> System.out.println("1"); } switch (i) { case Byte d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Short d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Integer d -> System.out.println("1");//error } switch (i) { case Long d -> System.out.println("1");//error } switch (i) { case Float d -> System.out.println("1");//error } switch (i) { case Double d -> System.out.println("1");//error } switch (i) { case Number d -> System.out.println("1");//error } switch (i) { case Object d -> System.out.println("1"); } } private static void testByte() { byte i = 0; switch (i) { case char d -> System.out.println("1"); default -> throw new IllegalStateException("Unexpected value: " + i); } switch (i) { case byte d -> System.out.println("1"); } switch (i) { case short d -> System.out.println("1"); } switch (i) { case int d -> System.out.println("1"); } switch (i) { case long d -> System.out.println("1"); } switch (i) { case float d -> System.out.println("1"); } switch (i) { case double d -> System.out.println("1"); } switch (i) { case Character d -> System.out.println("1");//error } switch (i) { case Byte d -> System.out.println("1"); } switch (i) { case Short d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Integer d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Long d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Float d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Double d -> System.out.println("1");//error default -> System.out.println("1"); } switch (i) { case Number d -> System.out.println("1"); } switch (i) { case Object d -> System.out.println("1"); } } }