Lambda with one parameter in Java
Forums:
//explicitly specify return type
Function<Integer, Integer> powOfTwo =
(Integer power) -> (int)Math.pow(2, power);
int pow8 = powOfTwo.apply(8);
//pow8 is 256
//implicitly specify return type
Function<Double, Double> powOfThree = power -> Math.pow(3, power);
double pow3 = powOfThree.apply(3.0);
//pow3 is 27.0
- Log in to post comments