黑马程序员
方法引用
package MethodReference;
@FunctionalInterface
public interface Printable {
void print(String str);
}
package MethodReference;
public class Printable_Demo {
public static void main(String[] args) {
printString(s->System.out.println(s));
System.out.println("************************");
printString(System.out::println);
}
public static void printString(Printable printable){
printable.print("Hello,World");
}
}
方法引用–通过对象名引用成员变量
package MethodReference02;
@FunctionalInterface
public interface Printable {
void print(String str);
}
package MethodReference02;
public class MethodRerObject {
public void PrintUpperCassString(String str) {
System.out.println(str.toUpperCase());
}
}
package MethodReference02;
public class Reference_Demo {
public static void printString(Printable printable){
printable.print("Hello");
}
public static void main(String[] args) {
printString((s)->{
new MethodRerObject().PrintUpperCassString(s);
});
printString(new MethodRerObject()::PrintUpperCassString);
}
}