What's the difference between instance method reference types in Java 8?
myString::charAt
would take anint
and return achar
, and might be used for any lambda that works that way. It translates, essentially, toindex -> myString.charAt(index)
.String::length
would take aString
and return anint
. It translates, essentially, tostring -> string.length()
.String::charAt
would translate to(string, index) -> string.charAt(index)
.
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.