I'm trying to implement a String like a command in Java:
public static void main(String[] args) {
String command = "System.out.println("hello word");";
...
}
I need to convert the command String to a command line, in order to execute output "hello word" in the console. I want to using to this technology to improve code:
SimpleDateFormat sdf = new SimpleDateFormat("MMMM");
String month = sdf.format(calIndex.getTime());
switch (month) {
case "January":
leaveDetailCLateLEarly.february += 10;
break; }
...
The above is quite verbose. I want to write something shorter:
String command = "leaveDetailCLateLEarly."+ month + "+= 10"
Where leaveDetailCLateLEarly is an object and having as an attribute the 12 months. (ie January, February, etc...) Then I have command string: 'leaveDetailCLateLEarly.month= 10' where the month value is able to change (January, February, March, ... ). When project runs, the String will convert to a command line to implement the desired functionality.