I have a name of a class in a string object. Is there a way to call
that class using its name in a string object? I am using reflection
and I have the name of the class; is there a way to call it using that
name?
Thanks
Lew - 22 Oct 2007 17:05 GMT
> I have a name of a class in a string object. Is there a way to call
> that class using its name in a string object? I am using reflection
> and I have the name of the class; is there a way to call it using that
> name?
<http://java.sun.com/javase/6/docs/api/java/lang/Class.html#forName(java.lang.String)>

Signature
Lew
Lew - 22 Oct 2007 17:14 GMT
>> I have a name of a class in a string object. Is there a way to call
>> that class using its name in a string object? I am using reflection
>> and I have the name of the class; is there a way to call it using that
>> name?
>
> <http://java.sun.com/javase/6/docs/api/java/lang/Class.html#forName(java.lang.String)>
By the way, there is no way to "call [a] class" in Java. You can only call
methods and constructors.

Signature
Lew
Roedy Green - 22 Oct 2007 17:58 GMT
>I have a name of a class in a string object. Is there a way to call
>that class using its name in a string object? I am using reflection
>and I have the name of the class; is there a way to call it using that
>name?
see http://mindprod.com/jgloss/classforname.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Daniel Pitts - 22 Oct 2007 19:24 GMT
> I have a name of a class in a string object. Is there a way to call
> that class using its name in a string object? I am using reflection
> and I have the name of the class; is there a way to call it using that
> name?
>
> Thanks
You don't call a class. You can load a class and instantiate it, its
called Reflection.
Don't use reflection! Well, don't use it unless you have a *REALLY*
good reason to.
<http://virtualinfinity.net/wordpress/program-design/2007/01/11/the-
dangers-of-reflection-or-put-down-that-mirror/>
Having said that, if you really want to know how, google for Java
Reflection. You can load classes, instantiate objects, call methods,
access fields, etc...
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>