mercredi 2 octobre 2019

Getting a variable's name using reflection

Hello I was wondering if it is possible to get a passed down variable name.
For example:

String variableTest = "Test variable";

System.out.println(getVariableName(variableTest ));

String getVariableName(Object object) {
    return object.getName(); // getting name here, idk how.
}

Then the returned value would be variableTest which is the name of the field.
Is it possible? All I want is to be able to get it without the player needing to type a string with it's name on it.





Aucun commentaire:

Enregistrer un commentaire