What's the difference between instance method reference types in Java 8?

筅森魡賤 提交于 2019-11-27 01:27:38
Louis Wasserman

1) myString::charAt would take an int and return a char, and might be used for any lambda that works that way. It translates, essentially, to index -> myString.charAt(index).

2) String::length would take a String and return an int. It translates, essentially, to string -> string.length().

I'm not even sure if String::charAt would translate to (string, index) -> string.charAt(index). I'd kind of expect it to, though.

With this they mean that you have the following:

1) Can be for example this::someFunction;, this will return the someFunction reference of the current object.

2) Can be for example String::toUpperCase, this will return the toUpperCase method of String in general.

I am not sure if there is an actual difference in behaviour, I think it is just like you can also call static methods on instance variables.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!