dimanche 20 septembre 2015

How to get Enum when it's string representation and type are known at Runtime?

Suppose I have an Enum as:

com.mypackage.enums

public enum Days {

    MONDAY,
    TUESDAY,
    WEDNESDAY
}

Now somewhere I know that I need to get enum MONDAY from a runtime string provided as "MONDAY". I also know that this enum lies in com.mypackage.enums.Days

How can I do this? With or without reflection?

EDIT: Both the string "MONDAY" and Class com.mypackage.enum.Days are determined at Runtime.





Aucun commentaire:

Enregistrer un commentaire