我有一个像这样的抽象类
public abstract class Command {
public abstract void execute(String keyWord[]);
String keyWord;
public Command(String keyWord) {
this.keyWord = keyWord;
}
}
和一个像这样管理它的类:
public class CommandManager {
private static List<Command> commands = new ArrayList<>();
public static void append(Command command) {
commands.add(command);
}
static {
}
public static void load() {
append(new Command("lol") {
@Override
public void execute(Player player, String[] keyWord) {
System.out.println("hi");
}
});
}
public boolean handle() {
String cmd[] = input.split(" ");
Command command = commands.get(cmd[0].toLowerCase()); //this
if (command != null) {
command.execute(player, cmd);
return true;
}
return false;
}
}
我得到的错误是我的评论所在。如何使用 get 方法从 Command 类中获取字符串?谢谢