Last active
August 3, 2020 13:21
-
-
Save GoncaloPT/a10361f9ce591664dba4bc74331d21c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why do we need the ::apply in line 18