java - Access private enum in legacy code in -


I have a legacy code where there is a personal command that requires another type of construction for the acceptance test, but I I am stuck because this Enum is private and it is not part of any class, it looks like the following:

  enum element {element1, ELEMENT2; Public static element [] value () {/ * compiled code * /} public static element element object (java.lang.String name) {/ * compiled code private entity () {/ * compiled code *}} < / Code> 

Are there ways to use this anman, highlight it with a legacy code, or how to duplicate it?

Update: I know that I can read values ​​by reflection, but I have another class which is public and I need to use enum value in my constructor, this class element The public class Element Provider {The name of the element, the element element} Pre>

One way to do this is to use Class.forName and load it by package + name.

For example:

  class  

Then if everything is ok then you will have enum.

Then with getEnumConstants you can read all the stages of enum ( you can check whether it is using isEnum If an enum is necessary ):

  object [] enumElements = elements.getEnumConstants (); For (object obj: enumElements) {System.out.println (obj); }  

You are forced to use the object because you do not know how it will be (well, you know but you can access it Can not be used)

and enumElements [0] to use ELEMENT1 and so on.


Regarding your updated question, this is the first thing that comes to my mind:

  class  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -