对象方法的引用
2017-10-09 14:24
148 查看
/** * 对象方法引用 * ClassName:instRef <br/> * Function: TODO ADD FUNCTION. <br/> * Reason: TODO ADD REASON. <br/> * Date: 2017年9月9日 下午1:28:06 <br/> * @author: Lelonta * @version * @see * * 类名::instmethod */ public class instRef { /** * 抽象方法没有输入参数 就不能使用对象方法引用 * * * 以下都不能用 * not: (这里用一句话描述这个方法的作用).<br/> * @author: Lelonta */ public void not() { Runnable runnable = () -> {}; Closeable closeable = () -> {}; Supplier<String> supplier = () -> ""; } public static void main(String[] args) { /** * 对象方法的引用 * Consumer<Q,String,Integer> 与 (Q q,String str,Integer int) 最好是自定义的类型 * | * ~ * new Q() * 第一个参数类型是恰好是自定义的Q类 , 剩下的参数是方法的参数 * Execute中的抽象方法 * run(W w,String name,String size) W中的run方法 * * class W run(String nameString,String sizeString) * 泛型中的参数 与 lambda表达式中的第一个参数相同 */ Consumer<Q> c1 = (Q q) -> new Q().qq(); Consumer<Q> c2 = Q::qq; c1.accept(new Q()); c2.accept(new Q()); BiConsumer<W, String> bc1 = W::getQ; bc1.accept(new W(), "abc"); BiFunction<W , String, Integer> bf1 = W::getQ; System.out.println(bf1.apply(new W(), "abcdg")); Execute ex = (w,name,size) -> new W().run(name, size); Execute execute = W::run; } } class Q { public void qq() { System.out.println("懂了吗?"); } } class W { public int getQ(String str) { return str.length(); } public void run(String nameString,String sizeString) { } } interface Execute { public void run(W w,String name,String size); }
相关文章推荐
- javascript引用对象的方法代码
- 非静态的字段、方法或属性“System.Web.UI.Page.ClientScript...”要求对象引用 (封装注册脚本)
- C++中const引用的是对象的时候只能调用该对象的f()const方法
- 对象方法和类方法的区别--引用
- js面向对象开发(四) 其他引用类型(encodeURI 、encodeURIComponent编码,eval方法 ,escape unescape 给汉字转码 )
- 从JVM内存管理的角度谈谈静态方法和静态属性 和 java对象引用与JVM自动内存管理
- Java面向对象-方法的值传递和引用传递
- 向方法传递对象引用变量时向前看....
- 非静态的字段、方法或属性“System.Web.UI.Page.ClientScript.get”要求对象引用
- Spring 使new方法创建的对象可以引用spring管理的bean.
- 引用 1.9.1.min.js dom对象 没有live 绑定事件方法, 引用 1.7.js 就有live 绑定事件方法
- javascript使用方括号([])引用对象的属性和方法
- Java 把对象作为参数传到一个方法里,这个是值传递还是引用传递, 为什么结果这么怪?
- 类与对象,引用传递的分析,private封装性,构造方法,
- asp.net “非静态字段、方法或属性’System.Web.UI.Page.Response.get‘要求对象引用”
- Java面向对象02-方法的签名,重载,构造方法和引用类型数组
- VS2015 新建项目提示 未将对象引用设置到对象的实例 解决方法
- VS提示“非静态的字段、方法或属性要求对象引用”
- System.out.println(s) 打印值为对象引用时,调用toString()方法。
- js中判断Object、Array、Function等引用类型对象是否相等的方法