I want do a log method to help with variables and their values, I want to do something like:
void log(Object object) {
android.util.Log.d("TAG", "The variable " + <One way to get object name here> + " has the value " + object);
}
and when I run something like this:
int hits = 12;
Object obj = null;
String s = "nhe nhe nhem";
log(hits);
log(obje);
log(s);
I want to get the following output:
The variable hits has the value 12
The variable obj has the value null
The variable s has the value nhe nhe nhem
I just need one way to get the variable name, I don't know anything similar in java, but if anyone knows one way to do it....
EDIT
I did an example in python that works fine:
myVariableWithSomeFooName = 32
for key, value in list(locals().iteritems()):
if id(value) == id(myVariableWithSomeFooName):
itemName = key
print "The " + str(itemName) + " has the value " + str(myVariableWithSomeFooName)