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 / First Aid / July 2005

Tip: Looking for answers? Try searching our database.

Classloader or whatelse?

Thread view: 
Novello - 01 Jul 2005 15:13 GMT
Hello,

My program needs to create a class, see code below to understand ;-)

/**
 * Loads system's class and execute it
 */
private static void loadSystem(String systemName,String symbol) {

      // wrong code:
      systemName system = new systemName(symbol);

}

the first param is systemName, the name of the class to create.
I cannot create it such as "systemName system = new sytemName(symbol)"
because systemName is a String and not a Class.

How can I solve this problem?

If something is not clear please ask, I will explain better :-)

thank you
Dale King - 01 Jul 2005 15:25 GMT
> Hello,
>
[quoted text clipped - 15 lines]
>
> How can I solve this problem?

Check out the java.lang.Class class. Specifically the forName static
method. To create a newInstance you can use the newInstance method, but
that only works for the no-arg constructor. To actually pass args you
have to use getConstructor to get the correct constructor which you can
then call newInstance on passing the args.

Signature

 Dale King



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



©2010 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.