Interfaces for the Java Command Template

Is there a library that already provides the interfaces needed for a command template in Java?

For instance:

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.

+6
source share
1 answer

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

More interestingly, Guava also has many methods using these two interfaces, for example Iterables.any(Iterable, Predicate) , Iterables.transform(Iterable, Function) , etc.

+6
source

Source: https://habr.com/ru/post/914677/


All Articles