????Java 8 ????????????????????2014??3??18?????ο???????????Java????????????????????????е??????????????????????????lambda??????????????????????????????????Java 8???????????????????????е???????????????6?д????????????????????д?????????м????????Lambda??????????????????????壬?????ú????????д????????????????????????????????Java??????У????????????????????????????????????????????????????????е?????????????????????CPU?????????????????????Java 8??????????κ??????Java????????????????Java????????????????lambda?????????????????API???????????μ?Date???Time API???????????????????????????lambda??????????????????????????????lambda???????????????Java 8?????????????Java???????Java Collections framework??????????????API??lambda????????????б??Lists????????Collections???????????????????????????????й???Java 8??д????????????????Щ????????????????Java 8?????????????????????10??lambda????????÷???????Щ???????С????????????????????lambda??????
????Java 8 lambda???????
??????????Java 8???????????????????lambda????????API?????????????????????д???????????????????????????????????ο?????lambda????д??????Java??????????????????????е?????????????????Java??ò??????????????????????????Щlambda????????API????????????????????????????Java???????е??????????????μ?????????????????????????????????Java 1.4??????????????У???????????????÷??????????????????????????????????????????η??lambda???????????????????????????????????????????????????????????????????????????????????????Java 8 lambda??????????e????????????????
??????1????lambda???????Runnable
???????????Java 8????????????????lambda?????滻???????????Runnable???????????????????????Java 8????runnable???????????4?д????????lambda??????????д????????????????????????????() -> {}????????????????????
????// Java 8????
????new Thread(new Runnable() {
????@Override
????public void run() {
????System.out.println("Before Java8?? too much code for too little to do");
????}
????}).start();
????//Java 8?????
????new Thread( () -> System.out.println("In Java8?? Lambda expression rocks !!") ).start();
?????????
????too much code?? for too little to do
????Lambda expression rocks !!
?????????????????????Java 8 lambda??????????????????lambdaд?????′???
????(params) -> expression
????(params) -> statement
????(params) -> { statements }
???????磬??????????????????????????д??????????????????????????????????д??
????() -> System.out.println("Hello Lambda Expressions");
??????????????????????????????????д????????????
????(int even?? int odd) -> even + odd
????????????????????lambda??????????????????????Щ?????????????????????????С?????????????????У??????????a??b????x??y???even??odd??á?
??????2?????Java 8 lambda???????????????
??????????ù?Swing API?????????????д??????????????????????汾??????????????????????????????????????????lambda????д???????????????????????????
????// Java 8????
????JButton show =  new JButton("Show");
????show.addActionListener(new ActionListener() {
????@Override
????public void actionPerformed(ActionEvent e) {
????System.out.println("Event handling without lambda expression is boring");
????}
????});
????// Java 8?????
????show.addActionListener((e) -> {
????System.out.println("Light?? Camera?? Action !! Lambda expressions Rocks");
????});
????Java?????????????????????????????? Collections.sort() ???? Comparator????Java 8?У??????????????lambda?????????a?????????????????????????ò??????????????????lambda??????? Runnable ?? ActionListener ??????е???·??????
??????3?????lambda???????б???е???
????????????????Java????????????????????????????е??????????????????????????????紦??????????????????б??????Java????????????Java 8????????????????????????????????????в??л??????????????????й??????????д?????????????????????????lambda??????????????????????????????????????????ζ??Java???????????????????????????????API?????????????в??д??????????????????????????????lambda?????lambda??????????μ????б???????????б???????????? forEach()  ??????????????????ж??????????lambda????????????С?
????// Java 8????
????List features = Arrays.asList("Lambdas"?? "Default Method"?? "Stream API"?? "Date and Time API");
????for (String feature : features) {
????System.out.println(feature);
????}
????// Java 8???
????List features = Arrays.asList("Lambdas"?? "Default Method"?? "Stream API"?? "Date and Time API");
????features.forEach(n -> System.out.println(n));
????// ???Java 8????????????????????????::?e????????????
????// ????????C++????????????????
????features.forEach(System.out::println);
?????????
????Lambdas
????Default Method
????Stream API
????Date and Time API
?????б???????????????????????Java 8????÷????????method reference????????????C++??????e?????Χ????????????????Java 8????????????????á?