import java.util.*; class GetClass { native void unknown(); void testStability(Object obj, Class c) { if (obj.getClass().equals(c)) { unknown(); if (obj.getClass().equals(c)) { } } if (obj.getClass().equals(ArrayList.class)) { unknown(); if (obj.getClass().equals(ArrayList.class)) { } } } void testFinalClass(String s) { if (s.getClass() == String.class) { } if (String.class.equals(s.getClass())) {} } void testNew() { Object x = new HashSet(); if (x.getClass() == HashSet.class) {} } void testInstanceOfInterop(Object obj) { if (obj instanceof CharSequence) { if (obj.getClass() == Integer.class) {} } if (obj.getClass() == HashSet.class) { if (obj instanceof Set) {} if (obj instanceof LinkedHashSet) {} } if (obj instanceof HashSet) { if (obj.getClass() == HashSet.class) {} // possible but not always if (obj.getClass() == LinkedHashSet.class) {} // also possible } } void testInterfaceAbstract(Object obj, Class c) { if (obj.getClass() == CharSequence.class) {} if (obj.getClass().equals(Number.class)) {} if (c == Number.class || c == CharSequence.class) { if (obj.getClass() == c) {} } } void testIntermediateVar(Object obj) { Class c = obj.getClass(); if (c == Number.class) {} if (c == HashSet.class) { if (obj instanceof CharSequence) {} } if (obj instanceof CharSequence) { if (c == HashSet.class) {} } } void testTwoObjects(Object o1, Object o2) { if (o1 instanceof CharSequence && o2 instanceof Integer) { if (o1.getClass() == o2.getClass()) {} } if (o1.getClass() == o2.getClass()) { if (o1 instanceof String) { if(o2.getClass() == Integer.class) {} } if (o1 instanceof CharSequence) { if (o2 instanceof Integer) {} } } } }