Util { public static boolean isInstance(Class type, Object instance) { if (type.isPrimitive()) { if (instance == null) { return false; } if (type.equals(boolean.class)) { return instance instanceof Boolean; } else if (type.equals(char.class)) { return instance instanceof Character; } else if (type.equals(byte.class)) { return instance instanceof Byte; } else if (type.equals(short.class)) { return instance instanceof Short; } else if (type.equals(int.class)) { return instance instanceof Integer; } else if (type.equals(long.class)) { return instance instanceof Long; } else if (type.equals(float.class)) { return instance instanceof Float; } else if (type.equals(double.class)) { return instance instanceof Double; } else { throw new AssertionError("Invalid primitve type: " + type); } } return instance == null || type.isInstance(instance); } private  Util(); static boolean isInstance(Class type, Object instance); static void addProperty(Hashtable env, String property); static Method findSetter(Class<?> testClazz, Field field, Object propertyValue); static Method getMostSpecificMethod(Method method1, Method method2);  }
@Test public void testIsInstance() { checkIsInstance(true, Object.class, null); checkIsInstance(true, Object.class, "String"); checkIsInstance(true, String.class, "String"); checkIsInstance(false, Integer.class, "String"); checkIsInstance(false, int.class, null); checkIsInstancePrimitive(boolean.class, true); checkIsInstancePrimitive(char.class, 'a'); checkIsInstancePrimitive(byte.class, (byte) 1); checkIsInstancePrimitive(short.class, (short) 1); checkIsInstancePrimitive(int.class, 1); checkIsInstancePrimitive(long.class, 1L); checkIsInstancePrimitive(float.class, 1.0f); checkIsInstancePrimitive(double.class, 1.0); }