Lambda表达式


package
threadtest; import java.util.Comparator; import org.junit.Test; public class Lambda { @Test public void test() { Runnable r1=new Runnable() { @Override public void run() { System.out.println("我爱祖国"); } }; r1.run(); //Lambda表达式 Runnable r2=()->System.out.println("爱我中华"); Runnable r21=()->{ System.out.println("爱我老师"); }; r2.run(); r21.run(); } @Test public void test2() { Comparator<Integer> COM1=new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { // TODO Auto-generated method stub return Integer.compare(o1, o2); } }; System.out.println(COM1.compare(111, 158)); //Lambda表达式 Comparator<Integer> COM=(o1, o2)->Integer.compare(o1, o2);{ System.out.println(COM.compare(11, 158)); }; //方法引用 Comparator<Integer> COM3=Integer::compare; System.out.println(COM.compare(1111, 158)); } }
原文地址:https://www.cnblogs.com/ylblikestudyJava/p/12403537.html