第三方类client: public class Client { public Integer add(Integer i, Integer j) { System.out.println("i+j=" + (i + j)); return i + j; } } 只用来做lambda的接口: @FunctionalInterface public interface ESCallBack<T> {
public T doSearch(Client client); }
桥接类,其中search1,search2就是给当前项目用的 : public class NativeMethodClient {
private Client client;
public NativeMethodClient(Client client) { this.client = client; }
private <T> T execute(ESCallBack<T> action) {
Preconditions.checkNotNull(action, "Callback object must not be null"); return action.doSearch(client); }
public Integer search1() { return execute((c) -> c.add(10, 20)); }