Skip to content

Instantly share code, notes, and snippets.

@stijn1989
Created October 14, 2021 15:55
Show Gist options
  • Save stijn1989/ad85ffea204c45568af90749fa8c7d99 to your computer and use it in GitHub Desktop.
Save stijn1989/ad85ffea204c45568af90749fa8c7d99 to your computer and use it in GitHub Desktop.
some fun with functions
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