public static Class < ? > getNamedClass ( Object obj ) { Class < ? > cls = getClass ( obj ) ; while ( cls != null && cls . isAnonymousClass ( ) ) { cls = cls . getEnclosingClass ( ) ; } return cls ; }
If the object is not a Class get its Class . Otherwise get the object as a Class . If the class is anonymous get a non - anonymous enclosing class .