java - Get the class in which an enum is declared -
java - Get the class in which an enum is declared -
this java question regarding enum.
i have these classes:
class test{ public static enum testenum implements variable{ test_something ; } } class main{ public static void main(string[] args){ //how class object test var? variable var = testenum.test_something; } }
so, how class object test
variable variable
value test.testenum.test_something
?
you can utilize reflection so:
class<?> testclass = testenum.test_something.getclass().getdeclaringclass();
the phone call getclass()
returns class object describing testenum
enum, "class" of test_something
. ensuing phone call getdeclaringclass()
returns test
, test
class in testenum
declared (its declaring class).
here finish documentation of java.lang.class
, starting point practically reflective operation.
java enums
Comments
Post a Comment