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 楼答案
Guava有第一个和第三个接口(称为
Function
和Predicate
)。第二个接口IMHO没有用处,因为您只需要将T1和T2组合到一个对象中,然后使用第一个接口更有趣的是,番石榴还有很多方法使用这两个接口,比如
Iterables.any(Iterable, Predicate)
,Iterables.transform(Iterable, Function)
,等等