OnJava8-Examples/innerclasses/MethodReferences.java

23 lines
640 B
Java
Raw Normal View History

2015-05-27 18:27:06 -07:00
//: innerclasses/MethodReferences.java
import java.util.*;
public class MethodReferences {
static class Description {
String describe;
public Description(String desc) {
describe = desc;
}
public void show() { System.out.println(describe); }
}
public static void main(String[] args) {
List<String> keys = Arrays.asList(
"Every", "Good", "Boy", "Deserves", "Fudge");
keys.forEach(System.out::println); // (1)
List<Description> descriptions = new ArrayList<>();
for(String k : keys)
descriptions.add(new Description(k));
descriptions.forEach(Description::show); // (2)
}
} ///:~