package java8;
@FunctionalInterface
interface Convert<T, F> {
T convert(F form);
default void run() {
System.out.println("hello world");
}
}
@FunctionalInterface
interface Convert1<T, F> {
T convert(F form);
default void run() {
System.out.println("hello world");
}
}
public class LambdaTest002 {
public static void main(String[] args) {
// lambda实质对应的是匿名方法
// 函数式接口编程编程,每个lambda表达式都对应一个类型,通常是接口类型
// (form)->Integer.parInt(form);对应着new
Convert<Integer, String> con = (form) -> Integer.parseInt(form);
Convert<Integer, String> con1 = new Convert<Integer, String>() {
public Integer convert(String form) {
return Integer.parseInt(form);
}
};
con1.run();
Integer i = con.convert("123");
con.run();
System.out.println(i);
}
}