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?
You are looking for the
Class.getDeclaringClass()method: