Skip to content

re: How to Write a Multiline Lambda in Java 8 VIEW POST


The Java lambda syntax allows single line statements or statement blocks which can be arbitrarily long. So the isBark predicate is good and reusable but you could stuff as many lines as you like into the lamba:

Predicate<Animal> isDog = animal -> { 
    try {
        Sound sound = animal.getSound();
        return sound.equals(Sound.valueOf("bark")); 
    } catch (MuteAnimalException e){ 
        logger.severe(e.getMessage); return false; 

That is true, and reminds me of a change I had thought of for my single line lambda demo. brb, editing example

code of conduct - report abuse