I have a method that accepts an Event like this:
addEvent(Event event);
The Event constructor accepts a long type like this:
Event(long delayTime);
So, I can explicitly define an argument into addEvent like this:
addEvent(new ThermostatNight(2000)); //ThermostatNight=Event and 2000=delayTime
However, I want to extract Event and delayTime values from a text file, hold them in an array and then pass them into an addEvent() construct as I loop through the arrays.
I have been able to solve half of the problem. I used Long.parseLong to convert the String delayTime values from the text file into a long type and pass it into the Event construct like this:
addEvent(ThermostatNight(y)); // Where y = the converted long type delayTime
Now I just need to figure out how to convert the String event type from the text file, for example ThermostatNight, into an Event type so that the addEvent method will accept it like this:
addEvent(x(y)) // x = Event value; y = long value
Would Class.forName work for this? I have tried to use it on the events held in the array but I get a ClassNotFoundException. Here is a snippet of code showing what I am trying to do:
for(String e2 : array2){
try{
Class<?> className = Class.forName(e2);
System.out.println(className);
} catch (ClassNotFoundException e) {
System.out.println("Class not found");
}
}