我正在构建一个管理控制器,它像Flex 4.5中的终端仿真器一样工作。 服务器端是使用Java编程语言的tomcat服务器上的Red5。我可以存储函数名称在最终的hashmap中执行吗?
当用户在他的文本输入中输入命令时,该命令被发送到red5,在red5中检查命令是否存在,并在命令或参数不匹配时返回适当的输出或错误。
所以现在我使用if (command.equals("..") {} else if (command.equals(...
是否有存储功能的名称,或者应该在每个命令执行,执行它的函数的引用的方法吗?
例如:
// creating the hasmap
HashMap<String,Object> myfunc = new HashMap<String,Object>();
// adding function reference
myfunc.put("help",executeHelp);
或....
myfunc.put("help", "executeHelp"); // writing the name of the function
然后
void receiveCommand(String command, Object params[]({
myfunc.get(command).<somehow execute the referrened function or string name ? >
}
什么想法?
谢谢!
是的,这是更安全,更有条理。 – cherouvim
谢谢你!并感谢@cherouvim的评论! – ufk