문제

Is there a library out there that already provides the interfaces we need for the command pattern in Java?

For example:

 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); }

 ....

Thanks.

도움이 되었습니까?

해결책

Guava has your first and third interfaces (called Function and Predicate). Your second one, IMHO, is not useful, because you would just have to combine T1 and T2 in a single object, and use the first interface instead.

More interesting, Guava also has a whole lot of methods using these two interfaces, like Iterables.any(Iterable, Predicate), Iterables.transform(Iterable, Function), etc.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top