aspose file tools
The moose likes Java in General and the fly likes Check if class is an inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Check if class is an inner class" Watch "Check if class is an inner class" New topic
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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Check if class is an inner class
 
Similar Threads
Default constructors
Top level Class can be private,protected?
static modifiers
Marcus Exam No2 #57
jls - searching problems