interface Foo<T> {
T apply(T double1, T double2);
}
public class Test {
static void calculate(Double double1, Double double2, Foo<Double> func) {
double result = func.apply(double1, double2);
System.out.println(result);
}
public static void main(String[] args) {
double double1 = 100;
double double2 = 0.2;
calculate(double1, double2, new Foo<Double>() {
public Double apply(Double double1, Double double2) {
return double1 * (1+double2);
}
}::apply);
//^^^^^^^---- does it improve anything? (code will work without it)
}
}
I don't understand the use of the syntax ::apply
at the end of the anonymous class's construction. I don't understand why this doesn't cause a compilation error and I don't understand what it achieves.
If you remove ::apply
, the program works. So why use double colons in this instance?