dimanche 31 mai 2020

How can I get enum's field value using reflection?

Given an enum

    public enum Country {
      INDIA("New Delhi"),
      US("Washinton DC");

      private String capital;
      private Country(String capital) {
       this.captital = capital;
      }

      // getters & setters

}

How can I get the field values, given the fieldName "capital" and Country.class using reflection?





Aucun commentaire:

Enregistrer un commentaire