Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Call a class using its name (in String object)??

Thread view: 
Z - 22 Oct 2007 16:28 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
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/>


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.