I was experimenting with Lambdas in Java on IntelliJ IDEA… they have a sense of humor.
I was wondering how simple a lambda could get so…
final Supplier<Double> supplier = () -> 1d; double value = supplier.get();
A lambda (supplier) that produces a number (1) from no input. Pretty simple. What will happen to the code if I refactor supplier
to make it an inline expression?
double value = ((Supplier<Double>) () -> 1d).get();
Well… that’s kind of in line with casting and such. Not that nice looking… However, now the IDE tells me I can make a simplification… “Replace method call on lambda with lambda body…” let’s try that:
double value = 1d;
Yeah… hmmm… that’s a pretty simple “lambda” indeed… hah!