Skip to content

Instantly share code, notes, and snippets.

@GoncaloPT
Last active August 3, 2020 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GoncaloPT/a10361f9ce591664dba4bc74331d21c1 to your computer and use it in GitHub Desktop.
Save GoncaloPT/a10361f9ce591664dba4bc74331d21c1 to your computer and use it in GitHub Desktop.
package pt.goncalo.freeroam.lambda;
public class LambdaExpressions {
interface Payback<T>{
T apply(T origin, T rate);
}
static void calculate(Double origin, Double rate, Payback<Double> func){
double payback = func.apply(origin,rate);
System.out.println(payback);
}
public static void methodReferenceDoubt(){
double origin = 1000;
double rate = 0.1;
calculate(origin, rate, new Payback<Double>() {
@Override
public Double apply(Double origin, Double rate) {
return origin * (1+rate);
}
}::apply);
}
public static void main(String [] args){
new LambdaExpressions().methodReferenceDoubt();
}
}
@GoncaloPT
Copy link
Author

Why do we need the ::apply in line 18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment