Reputation: 394
How can I determine if a java.lang.Class object represents a class?
Other java types can be determined by methods like isEnum(), isAnnotation(), isInterface(). I'm missing a method for the class type.
Upvotes: 3
Views: 92
Reputation: 1074228
I think it's a matter of elimination:
if (!c.isEnum() && !c.isInterface() && !c.isArray() && !c.isAnnotation() && !c.isPrimitive()) {
// It's a class
}
...which isn't very satisfying, as you have to revisit that definition when new features are added to Java (like enums, annotations, ...).
Upvotes: 4