cancel
Showing results for 
Search instead for 
Did you mean: 

Create an instance of a class from class name

marina_plag
Explorer
0 Kudos

Hi,

I have the class name as a String variable. I need to create an instance from this class. How to do it in Java?

Thanks and regards, Marina

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello

see

[http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Class.html#forName(java.lang.String)]

and

[http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Class.html#newInstance()]

for Classes with paramterless constructor

or

[http://java.sun.com/j2se/1.4.2/docs/api/java/lang/reflect/Constructor.html#newInstance(java.lang.Object[])]

for Constructor with parameters

regards franz

Answers (0)