Hope the title is explanatory.
1 public void commander(){
2 Scanner input = new Scanner(System.in);
3 System.out.println("\nWelcome to my application."
4 + "\nType the command you want to use,"
5 + "or type 'exit' to close the program.");
6 while (input.next() != "exit") {
7 List<String> userInput = Arrays.asList(input.next().split(" "));
8 Class<? extends RunnableCommand> command = Commands.commandsMap().get(userInput.get(0));
9 userInput.remove(0);
10 // command.run(userInput); ?!
11 }
Line 8: RunnableCommand is an interface that provides the run() method, implemented by every Class that represents a command (inspired by policy pattern).
Line 10: Here's the problem. The run() method of every "command class" can have 1, 2 or 3 String(s) as input.
Is there a way to give every element of userInput as input for the run() method?