function的好处:将相似的业务逻辑放在一个函数里面
例子:用function实现从缓存+数据库取值
1.执行一个参数的function
public T getDataFromJimdb(String date, Function function) { T t=function.apply(date); return t; }
2.执行两个参数
public T getDataFromJimdbTwo(String param1, String param2, BiFunction function) { T t = function.apply(param1, param2); return t; }
3.执行多个参数
@FunctionalInterface public interface ThreeFunction { K apply(T t, U u, V v); } public T getDataFromJimdbThree(String param1, String param2, String param3,ThreeFunction function) { T t = function.apply(param1, param2, param3); return t; }