• Post Reply Bookmark Topic Watch Topic
  • New Topic

Name of an Object  RSS feed

 
Abhin Balur
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,

How do i get the name of some object(reference variable name) in java?

for example for the below code:

Paper papi = new Paper();

I want "papi" at runtime. How to do that?

Thanks
 
Campbell Ritchie
Marshal
Posts: 56530
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think that is possible. That sort of information is erased from the bytecode.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you want it for?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that any given object can have lots of references, and some of them don't even have names:



In the code above, "s", "t", "a[0]" and "m[0][0]" are all references to the same object.

And there are no accessible references at all to the String created below:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!