Error
The target type of this expression must be a functional interface while using Lambda Expressions in Java 8.
Error Type
Compile Time ( Java 8 )
Sample Code
Set<Integer> intSet = new HashSet<Integer>();
intSet.add(1);
intSet.add(2);
intSet.add(3);
intSet.add(4);
intSet.forEach(p->System.out::println);
Cause
Target or Lambda Body should be a function interface.
Possible Resolution
Specify function interface as the Lambda Body.
Set<Integer> intSet = new HashSet<Integer>();
intSet.add(1);
intSet.add(2);
intSet.add(3);
intSet.add(4);
intSet.forEach(p->System.out.println(p));
The target type of this expression must be a functional interface while using Lambda Expressions in Java 8.
Error Type
Compile Time ( Java 8 )
Sample Code
Set<Integer> intSet = new HashSet<Integer>();
intSet.add(1);
intSet.add(2);
intSet.add(3);
intSet.add(4);
intSet.forEach(p->System.out::println);
Cause
Target or Lambda Body should be a function interface.
Possible Resolution
Specify function interface as the Lambda Body.
Set<Integer> intSet = new HashSet<Integer>();
intSet.add(1);
intSet.add(2);
intSet.add(3);
intSet.add(4);
intSet.forEach(p->System.out.println(p));