public class SimplePrimitiveInstanceOfPattern { public static void main(String[] args) { testForBool(true); testForInt(1); testForLong(1); testForDouble(1); testForFloat(1); testForByte((byte) 1); testForChar((char) 1); testForShort((short) 1); testForBoolObject(true); testForIntObject(1); testForLongObject(1L); testForDoubleObject(1d); testForFloatObject(1f); testForByteObject((byte) 1); testForCharObject((char) 1); testForShortObject((short) 1); testForObject(1); testForNumber(1); } private static void testForBool(boolean source) { if (source instanceof boolean target) { } if (source instanceof int target) { } //error if (source instanceof long target) { } //error if (source instanceof double target) { } //error if (source instanceof float target) { } //error if (source instanceof byte target) { } //error if (source instanceof char target) { } //error if (source instanceof short target) { } //error if (source instanceof Boolean target) { } if (source instanceof Integer target) { } //error if (source instanceof Long target) { } //error if (source instanceof Double target) { } //error if (source instanceof Float target) { } //error if (source instanceof Byte target) { } //error if (source instanceof Character target) { } //error if (source instanceof Short target) { } //error if (source instanceof Object target) { } if (source instanceof Number target) { } //error } private static void testForInt(int source) { if (source instanceof boolean target) { } //error if (source instanceof int target) { } if (source instanceof long target) { } if (source instanceof double target) { } if (source instanceof float target) { } if (source instanceof byte target) { } if (source instanceof char target) { } if (source instanceof short target) { } if (source instanceof Boolean target) { } //error if (source instanceof Integer target) { } if (source instanceof Long target) { } //error if (source instanceof Double target) { } //error if (source instanceof Float target) { } //error if (source instanceof Byte target) { } //error if (source instanceof Character target) { } //error if (source instanceof Short target) { } //error if (source instanceof Object target) { } if (source instanceof Number target) { } } private static void testForLong(long source) { if (source instanceof boolean target) { } //error if (source instanceof int target) { } if (source instanceof long target) { } if (source instanceof double target) { } if (source instanceof float target) { } if (source instanceof byte target) { } if (source instanceof char target) { } if (source instanceof short target) { } if (source instanceof Boolean target) { } //error if (source instanceof Integer target) { } //error if (source instanceof Long target) { } if (source instanceof Double target) { } //error if (source instanceof Float target) { } //error if (source instanceof Byte target) { } //error if (source instanceof Character target) { } //error if (source instanceof Short target) { } //error if (source instanceof Object target) { } if (source instanceof Number target) { } } private static void testForDouble(double source) { if (source instanceof boolean target) { } //error if (source instanceof int target) { } if (source instanceof long target) { } if (source instanceof double target) { } if (source instanceof float target) { } if (source instanceof byte target) { } if (source instanceof char target) { } if (source instanceof short target) { } if (source instanceof Boolean target) { } //error if (source instanceof Integer target) { } //error if (source instanceof Long target) { } //error if (source instanceof Double target) { } if (source instanceof Float target) { } //error if (source instanceof Byte target) { } //error if (source instanceof Character target) { } //error if (source instanceof Short target) { } //error if (source instanceof Object target) { } if (source instanceof Number target) { } } private static void testForFloat(float source) { if (source instanceof boolean target) { } //error if (source instanceof int target) { } if (source instanceof long target) { } if (source instanceof double target) { } if (source instanceof float target) { } if (source instanceof byte target) { } if (source instanceof char target) { } if (source instanceof short target) { } if (source instanceof Boolean target) { } //error if (source instanceof Integer target) { } //error if (source instanceof Long target) { } //error if (source instanceof Double target) { } //error if (source instanceof Float target) { } if (source instanceof Byte target) { } //error if (source instanceof Character target) { } //error if (source instanceof Short target) { } //error if (source instanceof Object target) { } if (source instanceof Number target) { } } private static void testForByte(byte source) { if (source instanceof boolean target) { } //error if (source instanceof int target) { } if (source instanceof long target) { } if (source instanceof double target) { } if (source instanceof float target) { } if (source instanceof byte target) { } if (source instanceof char target) { } if (source instanceof short target) { } if (source instanceof Boolean target) { } //error if (source instanceof Integer target) { } //error if (source instanceof Long target) { } //error if (source instanceof Double target) { } //error if (source instanceof Float target) { } //error if (source instanceof Byte target) { } if (source instanceof Character target) { } //error if (source instanceof Short target) { } //error if (source instanceof Object target) { } if (source instanceof Number target) { } } private static void testForChar(char source) { if (source instanceof boolean target) { } //error if (source instanceof int target) { } if (source instanceof long target) { } if (source instanceof double target) { } if (source instanceof float target) { } if (source instanceof byte target) { } if (source instanceof char target) { } if (source instanceof short target) { } if (source instanceof Boolean target) { } //error if (source instanceof Integer target) { } //error if (source instanceof Long target) { } //error if (source instanceof Double target) { } //error if (source instanceof Float target) { } //error if (source instanceof Byte target) { } //error if (source instanceof Character target) { } if (source instanceof Short target) { } //error if (source instanceof Object target) { } if (source instanceof Number target) { } //error } private static void testForShort(short source) { if (source instanceof boolean target) { } //error if (source instanceof int target) { } if (source instanceof long target) { } if (source instanceof double target) { } if (source instanceof float target) { } if (source instanceof byte target) { } if (source instanceof char target) { } if (source instanceof short target) { } if (source instanceof Boolean target) { } //error if (source instanceof Integer target) { } //error if (source instanceof Long target) { } //error if (source instanceof Double target) { } //error if (source instanceof Float target) { } //error if (source instanceof Byte target) { } //error if (source instanceof Character target) { } //error if (source instanceof Short target) { } if (source instanceof Object target) { } if (source instanceof Number target) { } } private static void testForBoolObject(Boolean source) { if (source instanceof boolean target) { } if (source instanceof int target) { } //error if (source instanceof long target) { } //error if (source instanceof double target) { } //error if (source instanceof float target) { } //error if (source instanceof byte target) { } //error if (source instanceof char target) { } //error if (source instanceof short target) { } //error if (source instanceof Boolean target) { } if (source instanceof Integer target) { } //error if (source instanceof Long target) { } //error if (source instanceof Double target) { } //error if (source instanceof Float target) { } //error if (source instanceof Byte target) { } //error if (source instanceof Character target) { } //error if (source instanceof Short target) { } //error if (source instanceof Object target) { } if (source instanceof Number target) { } //error } private static void testForIntObject(Integer source) { if (source instanceof boolean target) { } //error if (source instanceof int target) { } if (source instanceof long target) { } if (source instanceof double target) { } if (source instanceof float target) { } if (source instanceof byte target) { } //error if (source instanceof char target) { } //error if (source instanceof short target) { } //error if (source instanceof Boolean target) { } //error if (source instanceof Integer target) { } if (source instanceof Long target) { } //error if (source instanceof Double target) { } //error if (source instanceof Float target) { } //error if (source instanceof Byte target) { } //error if (source instanceof Character target) { } //error if (source instanceof Short target) { } //error if (source instanceof Object target) { } if (source instanceof Number target) { } } private static void testForLongObject(Long source) { if (source instanceof boolean target) { } //error if (source instanceof int target) { } //error if (source instanceof long target) { } if (source instanceof double target) { } if (source instanceof float target) { } if (source instanceof byte target) { } //error if (source instanceof char target) { } //error if (source instanceof short target) { } //error if (source instanceof Boolean target) { } //error if (source instanceof Integer target) { } //error if (source instanceof Long target) { } if (source instanceof Double target) { } //error if (source instanceof Float target) { } //error if (source instanceof Byte target) { } //error if (source instanceof Character target) { } //error if (source instanceof Short target) { } //error if (source instanceof Object target) { } if (source instanceof Number target) { } } private static void testForDoubleObject(Double source) { if (source instanceof boolean target) { } //error if (source instanceof int target) { } //error if (source instanceof long target) { } //error if (source instanceof double target) { } if (source instanceof float target) { } //error if (source instanceof byte target) { } //error if (source instanceof char target) { } //error if (source instanceof short target) { } //error if (source instanceof Boolean target) { } //error if (source instanceof Integer target) { } //error if (source instanceof Long target) { } //error if (source instanceof Double target) { } if (source instanceof Float target) { } //error if (source instanceof Byte target) { } //error if (source instanceof Character target) { } //error if (source instanceof Short target) { } //error if (source instanceof Object target) { } if (source instanceof Number target) { } } private static void testForFloatObject(Float source) { if (source instanceof boolean target) { } //error if (source instanceof int target) { } //error if (source instanceof long target) { } //error if (source instanceof double target) { } if (source instanceof float target) { } if (source instanceof byte target) { } //error if (source instanceof char target) { } //error if (source instanceof short target) { } //error if (source instanceof Boolean target) { } //error if (source instanceof Integer target) { } //error if (source instanceof Long target) { } //error if (source instanceof Double target) { } //error if (source instanceof Float target) { } if (source instanceof Byte target) { } //error if (source instanceof Character target) { } //error if (source instanceof Short target) { } //error if (source instanceof Object target) { } if (source instanceof Number target) { } } private static void testForByteObject(Byte source) { if (source instanceof boolean target) { } //error if (source instanceof int target) { } if (source instanceof long target) { } if (source instanceof double target) { } if (source instanceof float target) { } if (source instanceof byte target) { } if (source instanceof char target) { } //error if (source instanceof short target) { } if (source instanceof Boolean target) { } //error if (source instanceof Integer target) { } //error if (source instanceof Long target) { } //error if (source instanceof Double target) { } //error if (source instanceof Float target) { } //error if (source instanceof Byte target) { } if (source instanceof Character target) { } //error if (source instanceof Short target) { } //error if (source instanceof Object target) { } if (source instanceof Number target) { } } private static void testForCharObject(Character source) { if (source instanceof boolean target) { } //error if (source instanceof int target) { } if (source instanceof long target) { } if (source instanceof double target) { } if (source instanceof float target) { } if (source instanceof byte target) { } //error if (source instanceof char target) { } if (source instanceof short target) { } //error if (source instanceof Boolean target) { } //error if (source instanceof Integer target) { } //error if (source instanceof Long target) { } //error if (source instanceof Double target) { } //error if (source instanceof Float target) { } //error if (source instanceof Byte target) { } //error if (source instanceof Character target) { } if (source instanceof Short target) { } //error if (source instanceof Object target) { } if (source instanceof Number target) { } //error } private static void testForShortObject(Short source) { if (source instanceof boolean target) { } //error if (source instanceof int target) { } if (source instanceof long target) { } if (source instanceof double target) { } if (source instanceof float target) { } if (source instanceof byte target) { } //error if (source instanceof char target) { } //error if (source instanceof short target) { } if (source instanceof Boolean target) { } //error if (source instanceof Integer target) { } //error if (source instanceof Long target) { } //error if (source instanceof Double target) { } //error if (source instanceof Float target) { } //error if (source instanceof Byte target) { } //error if (source instanceof Character target) { } //error if (source instanceof Short target) { } if (source instanceof Object target) { } if (source instanceof Number target) { } } private static void testForObject(Object source) { if (source instanceof boolean target) { } if (source instanceof int target) { } if (source instanceof long target) { } if (source instanceof double target) { } if (source instanceof float target) { } if (source instanceof byte target) { } if (source instanceof char target) { } if (source instanceof short target) { } if (source instanceof Boolean target) { } if (source instanceof Integer target) { } if (source instanceof Long target) { } if (source instanceof Double target) { } if (source instanceof Float target) { } if (source instanceof Byte target) { } if (source instanceof Character target) { } if (source instanceof Short target) { } if (source instanceof Object target) { } if (source instanceof Number target) { } } private static void testForNumber(Number source) { if (source instanceof boolean target) { } //error if (source instanceof int target) { } if (source instanceof long target) { } if (source instanceof double target) { } if (source instanceof float target) { } if (source instanceof byte target) { } if (source instanceof char target) { } //error if (source instanceof short target) { } if (source instanceof Boolean target) { } //error if (source instanceof Integer target) { } if (source instanceof Long target) { } if (source instanceof Double target) { } if (source instanceof Float target) { } if (source instanceof Byte target) { } if (source instanceof Character target) { } //error if (source instanceof Short target) { } if (source instanceof Object target) { } if (source instanceof Number target) { } } }