Hey! I have a function:
* you can read about 'def' method in my article at medium
But my teammate write such code:
And code execution output:
Exception in thread "main" java.lang.NullPointerException
Something goes wrong and NullPointerException (NPE) is thrown while main method is executing.
My function and I unexpect that someone pass `null` object as function input value. Hopefully, I have another function that could protect my `cubeVolume` one. Contract is function’s name.
Contract function is function that applied to input value before one is passed to target function. Where target function is…
What is more expressive and shorter Java function definition?
Function<Integer, Function<Integer, Integer>> sum = x -> y -> x + y;
var sum = def((Integer x) -> (Integer y) -> x + y);
In my opinion, the second definition is more expressive and shorter. If you agree with me I recommend to read further.
You can feel free to move to Conclusion part in order to read `def` method implementation.
Lambda expression has introduced at Java 8. And It looks like this:
Function<Integer, Integer> square = x -> x * x;
Looks pretty enough, is it? …