import java.util.ArrayList; import java.util.List; public class HistoryCommand2 implements Command2 { private final List commandHistory = new ArrayList<>(); @Override public String getName() { return "history"; } @Override public void execute(String[] args, List articles) { if (commandHistory.isEmpty()) { System.out.println("暂无历史记录"); return; } System.out.println("===== 命令历史 ====="); for (int i = 0; i < commandHistory.size(); i++) { System.out.println((i+1) + ". " + commandHistory.get(i)); } } public void addCommand(String cmd) { commandHistory.add(cmd); } }