Created
October 14, 2021 15:55
-
-
Save stijn1989/ad85ffea204c45568af90749fa8c7d99 to your computer and use it in GitHub Desktop.
some fun with functions
This file contains 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
import java.util.function.BiFunction; | |
public class Mqtt | |
{ | |
public double calculate(BiFunction<Double, Double, Double> calc, double a, double b) | |
{ | |
return calc.apply(a, b); | |
} | |
public static double sum(double a, double b) | |
{ | |
return a + b; | |
} | |
public static double divider(double a, double b) | |
{ | |
return a / b; | |
} | |
public static void main(String[] args) | |
{ | |
var m = new Mqtt(); | |
System.out.println("Som: " + m.calculate(Mqtt::sum, 2,3)); | |
System.out.println("Divide: " + m.calculate(Mqtt::divider, 2,3)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment