[Java] Help with dynamic insantiation of classes

Discussion in 'Programming General' started by chrisrulz911, Aug 3, 2008.

[Java] Help with dynamic insantiation of classes
  1. Unread #1 - Aug 3, 2008 at 5:59 AM
  2. chrisrulz911
    Joined:
    Nov 1, 2005
    Posts:
    288
    Referrals:
    0
    Sythe Gold:
    0

    chrisrulz911 Forum Addict

    [Java] Help with dynamic insantiation of classes

    I've been trying to solve this problem for the past hour, and to no avail. This is the segment of code I'm working with:
    Code:
    	public void loadScripts(){
    		for(int i = 0; i < scriptNames.size(); i++){
    			Class c = Class.forName(scriptNames.get(i));
    			myScripts.add(c);
    		}
    	}
    
    What it does it takes a String name from the ArrayList scriptNames, and tries to instantiate a class and add it to the ArrayList myScripts

    The major goal is to go into a directory that contains java files, and allow the instantiation of any one of them. I managed to make a method that gives me the names of the java files in the directory, but I am stumped on the instantiation of the class.

    Any help would be appreciated!
     
< :) | What Language Next? >

Users viewing this thread
1 guest


 
 
Adblock breaks this site