How do I print the variable name holding my object?
For example, I have:
myclass ob=new myclass()
How would I print “ob”?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Objects don’t have names, unless you happen to be using a class which allows each object to be given one (e.g. via a variable retrieved with
getName()).In particular, the name of any particular variable used to refer to an object is completely unknown to the object itself. So you can’t do:
(Bear in mind that several variables could all refer to the same object, and there don’t have to be any named variables referring to an object.)