Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class.forName

 
S.Subhash Chandran
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating an instance of a new class dynamically:
Object obj = Class.forName(classNme).newInstance();
The problem is that, how do I pass values to the constructor of ``classNme''?
 
karl koch
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
from the Class object you can get the desired Constructor using:

and then create a new instance using:

check also the java.lang.reflect API description (online api)
k
[ May 26, 2003: Message edited by: karl koch ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic