• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class.forname

 
Mini Ramachandran
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I get the name of the "className" initialized here from another class (both in the same package)?
Class.forname("className").newInstance();
getClass().getName() gets the name of the class loaded.
Thanks.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what exactly you are asking... but are you looking for the class literal? TheClass.class.getName() will return "your.package.TheClass" and will instantiate TheClass if passed as argument to Class.forName().
- Peter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic