lundi 20 février 2017

How to get a method using java reflection with only partial name as a string of the method?

I am trying to invoke a getter of a class, I have only the partial name such as "Name", "age" etc. I need to invoke the method from class like getName/retriveName dynamically based on the getters using java Reflection api.

for eg:

class PersonData{

private String personName;
private int personId;
private int personAge;

public PersonData(){
}

public int getPersonId(){
    return this.personID;
}

public String getPersonName(){
    return this.personName;
}

public int getPersonAge(){
    return this.PersonAge;
}
}

I may get "name"/"Name" based on the user input, I should invoke the method getName() only. Kindly help.





Aucun commentaire:

Enregistrer un commentaire