Skip to content

Instantly share code, notes, and snippets.

@danilosilvadev
Last active April 27, 2021 21:07
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danilosilvadev/b42c87e4114c96844b121a882117de38 to your computer and use it in GitHub Desktop.
Save danilosilvadev/b42c87e4114c96844b121a882117de38 to your computer and use it in GitHub Desktop.
Lambda Expressions in less than 2 minutes

Sample:

Fact 1 - Consider the methods has 2 parts: HEAD(public void nameOfMethod(Input input)) and BODY({Everything inside the keys}).

//without lambda you still use the HEAD as always.
    public void printName() {
        System.out.println(“Print without lambda”);
    }
    
//The same code, but now with lambda you should just make the HEAD shorter letting just the signature there.
 () -> System.out.println(“Print with lambda”);
//If have some inputs:
 (valueString) -> {
    System.out.println(valueString);
};
//or the parentheses are optional in this case:
 valueString -> {
    System.out.println(valueString);
};

You learned lambda expressions in 2 minutes, well done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment