I'm trying to transform a simple if-else statement that I've found myself using all over the place to a more elegant lambda expression. But I'm having a hard time coming up with a solution from what I've been reading.
The simple statement goes like:
if (status.getStatus() == 'A') then
handleA();
else if (status.getStatus() == 'B') then
handleB();
else
handleEverythingElse();
I know I could use the Command pattern with a map, but I'm sure there's some Java 8 elegance that I'm missing. Could someone show me the interface & impl, as well as it's usage in the body of the code (I learn by example)?
Any help would be much appreciated!
switchstatement... But why do you want a lambda anyway? If it works, don't fix it, right?Function?() -> { /* your code above */ }.