Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get Class Name

 
jacob deiter
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI all

I have a Class ,inside that,how I get the name of the class.

For Ex:

class abc
{

// Here I need to get the name of the class.

}
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In an instance method, "this.getClass().getName()" will do it. In a static method, you really can't except using some pretty ugly and unreliable tricks using stack traces.
 
Rob Spoor
Sheriff
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But you know which class you are in - it's static so it only belongs to the class in which it is coded. Therefore, you know it's class "abc". And if you know it's class "abc", you can get the Class object using "abc.class". So the name can be retrieved using "abc.class.getName()".
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic