| Author |
Check if class is an inner class
|
Sebastian Janisch
Ranch Hand
Joined: Feb 23, 2009
Posts: 1183
|
|
Hey,
I'm trying to find out some of the metadata of a class.
The Modifier class offers pretty much most of what I need, however, I am trying to find out of a class is a non-static inner class and the Modifier API does not seem to provide that kind of information.
I could check if the class name contains '$' and then use the Modifier#isStatic() method but that seems cumbersome to me. Is there a smoother way to do that ?
Thanks
|
JDBCSupport - An easy to use, light-weight JDBC framework -
|
 |
Sebastian Janisch
Ranch Hand
Joined: Feb 23, 2009
Posts: 1183
|
|
I found the solution.
Class has a method #getEnclosingClass(). This method will return null if the class in question is a top level class.
So, getEnclosingClass() != null && Modifiers.isStatic(class.getModifiers()) does the trick.
|
 |
 |
|
|
subject: Check if class is an inner class
|
|
|