I am trying to understand why the following code compiles:
public class MethodRefs { public static void main(String[] args) { Function<MethodRefs, String> f; f = MethodRefs::getValueStatic; f = MethodRefs::getValue; } public static String getValueStatic(MethodRefs smt) { return smt.getValue(); } public String getValue() { return "4"; } }
I see why the first assignment is valid - getValueStatic explicitly matches the specified Function type (it takes a MethodRefs object and returns a String ), but the second one getValue me - the getValue method takes no arguments, so why is it still valid to assign it to f ?
java java-8
codebox Apr 20 '17 at 15:04 on 2017-04-20 15:04
source share