Issues with resolving overloaded methods – passing method references

You can define overloaded methods with different parameter types, as follows:

class Championship {
static boolean reward(Integer lapTime) {
return(lapTime < 60);
}
static boolean reward(String lap) {
return(lap.equalsIgnoreCase("final ");
}
}

However, the following code doesn't compile:

someMethod(Chamionship::reward);                     // ambiguous call

In the preceding line of code, since the compiler is not allowed to examine the method reference, the code fails to compile. This is unfortunate since the method parameters to the overloaded methods are Integer and String—no value can be compatible with both.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.0.85