Is there a way to get the compiler to choose the static method reference?
This code fails to compile because there are two methods that satisfy this method reference. Is there a way to hint or cast it so that it resolves the static method reference?
public class Number {
private final int value;
public Number(int value) {
this.value = value;
}
public Number add(int x) {
return operate(Number::add, x); // <---- compile fail here at Number::add
}
private Number operate(BiFunction<Number, Integer, Number> function, int x) {
return function.apply(this, x);
}
public static Number add(Number x, int y) {
return new Number(x.value + y);
}
}