有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Java中命令模式的接口

有没有一个库已经为Java中的命令模式提供了我们需要的接口

例如:

 public interface Func1<T,R> { public R execute(T input); }

 public interface Func2<T1,T2,R> { public R execute(T1 input1, T2 input2); }

 public interface Predicate1<T> { public boolean execute(T input); }

 ....

谢谢


共 (1) 个答案

  1. # 1 楼答案

    Guava有第一个和第三个接口(称为FunctionPredicate)。第二个接口IMHO没有用处,因为您只需要将T1和T2组合到一个对象中,然后使用第一个接口

    更有趣的是,番石榴还有很多方法使用这两个接口,比如Iterables.any(Iterable, Predicate)Iterables.transform(Iterable, Function),等等