How do you get the reference to the class object of an anonymous inner class in Java?
With non-anonimous class it is done with ClassName.class
.
How do you get the reference to the class object of an anonymous inner class in Java?
With non-anonimous class it is done with ClassName.class
.
If for reference to the anonymous you ask a reference to the anonymous class, the
java.lang.Class
instance object to your anonymous class here is how you can do that.If you assign the anonimous class instance to the variable
obj
you can have a reference to the class withobj.getClass()
. The example usesObject
, but any non-final
class and any interface can be used.You can do the same also without explicitly creating a variable like obj for example
If no reference to the an object of type 'Anonymous' can be used (at least with reflection) you can't do that.