package com.guahao.dap.mi.access.external.base;
import java.util.function.Function;
/**
* @author
* @version V1.0
* @since 2022/5/9 16:02
*/
public class Test2 {
public static void main(String[] args) {
System.out.println((Integer) set(1,(i)->i+2));
}
public static <T> T set(Integer i, Function<Integer, T> f){
return f.apply(i);
}
}
package com.guahao.dap.mi.access.external.base;
/**
* @author
* @version V1.0
* @since 2022/5/9 15:49
*/
public class Test1 {
public static void main(String[] args) {
Test1.get("aaa").dofunc(print1(),print2());
}
@FunctionalInterface
public interface Functions{
void dofunc(Runnable r,Runnable r1);
}
public static Functions get(String s){
return (r1,r2)->{
if(s.equals("aa"))
r1.run();
else
r2.run();
};
}
public static Runnable print1(){
return ()->{
System.out.println(111);
};
}
public static Runnable print2(){
return ()->{
System.out.println(222);
};
}
}
|