Java 8

Introduction to Functional Interface – Java8

What is Functional Interface? A functional interface is any interface which contains only one abstract method. A functional interface can have one or more default and static methods. Also, there is an annotation in Java @FunctionalInterface which is used to annotate the functional interfaces. It is not a mandate for functional interfaces to carry this annotation. There are many predefined functional interfaces in Java which belong to the package java.util.function What is the significance of these interfaces? These interfaces as we know declare a method which can be implemented and us...
Read More

Introduction to Lambda Expressions – Java8

What are Lambda Expressions? Lambda expressions are another way of writing inline unnamed code block which performs a simple function. Not a direct analogy but if you recall anonymous classes in Java they are a way of writing inline classes. On similar lines Lambda expressions are a way to write method body inline. They can be considered as anonymous methods, there is no need to formally define these methods but the code in the lambda expression is the body of the method. Lambda Expression Example If I want to write a print method which prints the content of a List of strings which is pa...
Read More