# 体验方法引用
方法引用的出现原因:
再使用 Lambda 表达式的时候,我们实际上传递进去的代码就是一种解决方案:那参数做操作
那么考虑一种情况:如果我们在 Lambda 中所指定的操作方案,已经有地方存在相同方案,那是否还有必要再写重复逻辑呢?答案是肯定没有必要
那我们又是如何使用已经存在的方案呢?
这就是我们要讲解的方法引用,我们是通过方法引用来使用已经存在的方法的。
方法引用简单概述:
把已经有的方法拿过来用,当做函数式接口中抽象方法的方法体

代码演示:
| public interface Printable { | |
| void printString(String s); | |
| } | |
| public class PrintableDemo { | |
| public static void main(String[] args) { | |
|         // 在主方法中调用 usePrintable 方法 | |
| //        usePrintable((String s) -> { | |
| //            System.out.println(s); | |
| //        }); | |
| 	    //Lambda 简化写法 | |
| usePrintable(s -> System.out.println(s)); | |
|         // 方法引用 | |
| usePrintable(System.out::println); | |
|     } | |
| private static void usePrintable(Printable p) { | |
| p.printString("爱生活爱Java"); | |
|     } | |
| } | 
