OnJava8-Examples/innerclasses/UnboundMethodReference.java
2015-05-27 18:27:06 -07:00

24 lines
596 B
Java

//: innerclasses/UnboundMethodReference.java
// Method reference without an object.
import java.util.*;
import java.util.function.*;
import static net.mindview.util.Print.*;
class X {
String f() { return "X.f()"; }
}
public class UnboundMethodReference {
public static void main(String[] args) {
Function<String, Integer> len = String::length;
print(len.apply("UnboundMethodReference"));
List<String> words =
Arrays.asList("Rain", "Spain", "Plain");
words.forEach(System.out::println);
Function<X, String> xfr = X::f;
print(xfr.apply(new X()));
}
} ///:~