• Log in or sign up for an account here: https://www.sythe.org/login

[Java] Help with dynamic insantiation of classes

chrisrulz911

Forum Addict
Joined
Nov 1, 2005
Sythe Gold
0
Messages
288
[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!
 
Runescape Gamblingrunescape gambling
Back
Top