this is a hard one for me (mostly because i'm not even sure what i'm looking for so ill try to explain the best i can). I want to have a few Engine class files (all will have the same methods but will use different calculations in them). then i want my main class to get the name of the class i choose and call the method inside the correct class. putting into pretty code something like this:
Engine1.java:
public static class Engine1{
doCoolStuff(){
//coolStuff happening
}
}
Engine2.java:
public static class Engine2{
doCoolStuff(){
//coolStuff happening in a different way
}
}
Main.java:
String EngineType = "Engine1";
public class Main{
public Main(){
(Class.forName(EngineType)).doCoolStuff();
}
}
this is pretty much the idea, im not even sure if thats the best way to do it but thats how far i've got for now, im also opened for suggestions if there's a better way for these kind of stuff in Java since im a little bit of a newbie there. obviously at the current state this code doesnt compile (because of the line: Class.forName(...).doCoolStuff(); "cannot resolve method"
EDIT :
this question has been answered already but i felt like its important to note that my code had another issue : the method Class.forName() required the FULL pathname of the class i.e not just "Engine1" but "com.packageName.Engine1". might save some people another 30 min :P