jeudi 26 mars 2015

Get value of variable by it's name : Java

I would like to get a variable's value by having variable's name, how can I achieve it ?



private String firstName = "myFName";
private String secondName = "mySName";

public void print(String fName , String sName){ // fName = "firstName" , sName = "secondName"

//print fName value which is actually "myFName"
//print sName value which is actually "mySName"
}


Thanks






Aucun commentaire:

Enregistrer un commentaire