views:

52

answers:

1

In a nutshell, I'm trying to do the inverse of "classObject.getDeclaredClasses()".

I have a method that receives an object of type Class<? extends Object>. I want to figure out whether it is an inner class, and if it is, I want to access the surrounding class' object instance.

Is there a smart API for this, or am I forced to do some string manipulation and parsing?

+4  A: 

You are looking for the Class.getDeclaringClass() method:

public Class getDeclaringClass()

If the class or interface represented by this Class object is a member of another class, returns the Class object representing the class in which it was declared. This method returns null if this class or interface is not a member of any other class. If this Class object represents an array class, a primitive type, or void,then this method returns null.

Returns: the declaring class for this class

abhin4v
Ugh, i feel stupid. Of course I'm looking for this. Thanks!
Henrik Paul