0
我希望用地图来访问我的方法,但我不能,如果他们有这样的参数来访问它们:地图和我自己的方法
public static void cmdCheck(String cmd, Stack<String> input) throws Exception{
cmd=cmd.substring(1,cmd.length());
Map<String, Method> cmdMap = new HashMap<String, Method>();
cmdMap.put("login", CommandDirectory.class.getMethod("subCmdCheck"));
if(cmdMap.containsKey(cmd)){
cmdMap.get(cmd).invoke(input.pop(), input);
}else{
System.out.println("UNKOWN COMMAND");
}
System.out.println("Done With Cmd Check");
}
public static Method subCmdCheck(String subCmd, Stack<String> input) throws Exception{
if(subCmd.indexOf("-")==0){
System.out.println("WORKING");
}else{
System.out.println("MISSING ESSENTIAL INFO, CORRECT USAGE:");
System.out.println(" .login //Incomplete");
System.out.println();
}
return null;
}
如何访问这些参数?
你预计会发生什么?您的方法签名不接受任何参数 – chenchuk
显示您尝试传递参数的内容,然后我们可以看到问题所在。 –
如果你想传递参数,你可能想要声明实际参数的方法。 – SLaks