File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Is possible to get variable name in java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Is possible to get variable name in java?" Watch "Is possible to get variable name in java?" New topic
Author

Is possible to get variable name in java?

Eswar Nec
Ranch Hand

Joined: May 02, 2010
Posts: 105
Hi,
I have two class. I want to get first class variable name. Not value.

First.java


Second.java


Is possible?
Help me.
Thanks in advance.


Wake up! Don't let your smile be snatched away by anybody!
Regards, Eswar
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Via reflection : Class#getFields() will return an array of fields. You can get their name via Field#getName()


[My Blog]
All roads lead to JavaRanch
subhash kumar
Ranch Hand

Joined: Jul 14, 2010
Posts: 63
try reflection.


Subhash Kumar
Attitude is everything
Eswar Nec
Ranch Hand

Joined: May 02, 2010
Posts: 105
Thanks Christophe Verré and subhash kumar for your support.

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Why do you need the variable name?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is possible to get variable name in java?
 
Similar Threads
can the following code produces Null pointer exception?‏
Final variables
Dan's GC Question Doubt
Doubt in data encapsulation !!
logic behind not able to assign a static value to a non static variable