Is int.class.isInstance(Object) a contradiction?
问题 Here's an example: public boolean check(Class<?> clazz, Object o) { return clazz.isInstance(o); } check(int.class, 7); // returns false Since isInstance accepts an Object , it won't work with int , because int is a primitive type and gets autoboxed to Integer . So is it at all possible to write a generic check method? Or should I make sure that clazz is of type Class<? extends Object> ? 回答1: Not all Class objects represent classes / reference types; there are also Class objects that represent