vendredi 12 novembre 2021

Java reflection - get getter method with different name

Is there any way I can get the getter method of a field, which is having different name from the usual standards?

class Employee {

        private String name;
        private String dept;

        public String getTheName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getTheDept() {
            return dept;
        }

        public void setDept(String dept) {
            this.dept = dept;
        }
    }

I know using reflection we can get the getter method of a field if the getter method is following the usual standard. Example:

  1. name ==> getName
  2. dept ==> getDept

But in our project, we are having a different convention than usual.

Thanks in advance.





Aucun commentaire:

Enregistrer un commentaire