????Java 8?????????????????????????????????JDK????????????????濴????JDK7???????6??8????????£?
??????8 ????Lambda?????????????????????????????????????????????????????????????????б??????o?????????????????·?????????????????Lambda????ó????????????????2??????檔
????Java??????Lambda
????1996??1?£?Java 1.0???????????????????????????????仯??????????????????????????????????????????????CPU???????????и?Ч?????????????Java???????JVM??????????ó??????????????????д???????????????????????????????ν?????CPU?????????????????á?
???????CPU????????“??????????”???????????????????????????????????????????????????????????????java.util.concurrent?????????????????????????????????????????д??????CPU?????????????????????????????????????????????
??????Щ????????????Java??????????????????????????????????????????????????Java??????Ч????в?????Java 8??????????д????????????????????????????????????????????CPU???Ч???С?????д???д?????Щ??????????????????????????????е?Java??????lambda??????
??????????????????д??????????????????α?д?????????lambda?????????????????????????????????д???θ???????????????????????????????Щ???????????????????????????????????????????????????????????????????????Ч???????????
?????????δ?????Lambda???????????????
????Lambda????ó???
???????б?????o??????????????純???????????????????????????????????????????????Щ???????????????????????????????????????д????????????????????????????
????1.???() -> {} ?????????
????????Runnable????Swing??JavaFX???????????????????java 8??????????Lambda?????????a????????
//Before Java 8:
new Thread(new Runnable() {
@Override
public void run() {
System.out.println("Before Java8 ");
}
}).start();

//Java 8 way:
new Thread(() -> System.out.println("In Java8!"));

// Before Java 8:
JButton show =  new JButton("Show");
show.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("without lambda expression is boring");
}
});


// Java 8 way:
show.addActionListener((e) -> {
System.out.println("Action !! Lambda expressions Rocks");
});
????2.????????????????
??????????????????????????????2???????for????????????????????????List?е?????
???????????????????????????????????????????????List?е????
//Prior Java 8 :
List features = Arrays.asList("Lambdas"?? "Default Method"??
"Stream API"?? "Date and Time API");
for (String feature : features) {
System.out.println(feature);
}

//In Java 8:
List features = Arrays.asList("Lambdas"?? "Default Method"?? "Stream API"??
"Date and Time API");
features.forEach(n -> System.out.println(n));

// Even better use Method reference feature of Java 8
// method reference is denoted by :: (double colon) operator
// looks similar to score resolution operator of C++
features.forEach(System.out::println);

Output:
Lambdas
Default Method
Stream API
Date and Time API
????3.?????????
?????????????????Java 8??????????μ??java.util.function??????????????java.util.function.Predicate?????Lambda????????
public static void main(args[]){
List languages = Arrays.asList("Java"?? "Scala"?? "C++"?? "Haskell"?? "Lisp");

System.out.println("Languages which starts with J :");
filter(languages?? (str)->str.startsWith("J"));

System.out.println("Languages which ends with a ");
filter(languages?? (str)->str.endsWith("a"));

System.out.println("Print all languages :");
filter(languages?? (str)->true);

System.out.println("Print no language : ");
filter(languages?? (str)->false);

System.out.println("Print language whose length greater than 4:");
filter(languages?? (str)->str.length() > 4);
}

public static void filter(List names?? Predicate condition) {
names.stream().filter((name) -> (condition.test(name)))
.forEach((name) -> {System.out.println(name + " ");
});
}

Output:
Languages which starts with J :
Java
Languages which ends with a
Java
Scala
Print all languages :
Java
Scala
C++
Haskell
Lisp
Print no language :
Print language whose length greater than 4:
Scala
Haskell