on 02-05-2008 11:13 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.