Heiko
Heiko

Reputation: 394

Determine if java.lang.Class object represents a class

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

Answers (1)

T.J. Crowder
T.J. Crowder

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

Related Questions