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.
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.
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, ...).
c.isAnnotation() test is obsolete, as annotations have been ruled out by !c.isInterface() already.
getClassreturns this class, you have to eliminate abstract classes. Etc etc. It's not really a very well-defined question; you have to refine it yourself, and the JDK isn't going to guess at what you mean.