From the course: Advanced Java Programming
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Implementing lambdas in Java - Java Tutorial
From the course: Advanced Java Programming
Implementing lambdas in Java
- [Bethan] Lambdas provide a short and simple way to implement functional interfaces in Java. They are now a commonly used feature in the Java language so it is useful to be able to read and understand them, as well as to use them in your own code. In this example I have a functional interface called greeting message which has a single abstract method called greet, then in my main class, I implement a new greeting message instance using an anonymous inner class. I override the greet message followed by the name parsed in. Instead of using all this boiler plate code, I can use a lambda instead to make the code shorter and simpler, so in the main method below the code I already have. I will create a second greeting message variable and I will call it gm2 and then put the equals sign. Now I need to use a pair of brackets, inside these brackets I put the variables that will be used in the greet method. This is exactly the same as the information in the brackets when I override the greet…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.