我正在用java编写一个shell实现,它支持通过向Map<String, Command>
添加一个Command
对象并编写与此命令关联的类来添加新命令。java:dynamic class cast
commandList.put("sort", new sort()); // sort extends Command
每个命令具有多个OptionsDefinition<T>
S的选项名称到使用Consumer<T>
物体的方法相关联的参考(T是类的命令的:排序例如)。
我要让引用的方法为了能够调用两次相同的命令在我的壳没有混合在同一个命令的属性值,所以我需要传递sort
型this
的非静态Consumer<sort>
在我的sort命令的例子中。
我想知道我怎么能改造一下我:
Command sort = commandList.getCommand("sort");
到:
sort sort = commandList.getCommand("sort");
能够使用
option.getCallback().process(sort); // sort is the reference to this
是否有可能做所以?
如果你只有一个'sort'的实现,我只需要使用那一个实现,不需要查看它。如果你有多个实现,我会使用一个强制转换。 –