This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes creating dynamic object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "creating dynamic object" Watch "creating dynamic object" New topic
Author

creating dynamic object

Reshma Reddy
Ranch Hand

Joined: Dec 21, 2006
Posts: 197
Hi,

how we can create object for a class dynamically.

Regards,
vishnu
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Using Class#forName and Class#newInstance ?


[My Blog]
All roads lead to JavaRanch
Reshma Reddy
Ranch Hand

Joined: Dec 21, 2006
Posts: 197
Hi,
i got your point, thaks for your replay.

Regards,
vishnu
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19911
    
  23

newInstance calls the constructor without arguments. If you need another one, use Class' getConstructor method, passing the argument types. If you want to find all constructors there's the getConstructors method.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
 
subject: creating dynamic object