IntelliJ IDEA anonymous class as Java 8 lambda
July 11, 2013 Leave a comment
I recently started coding lambdas. This is partly to prevent my Java skills from getting rusted.
I found that IntelliJ IDEA has this interesting feature that allows an inner class to be shown as a lambda.
public class Employee { public Employee( String name,int age){ this.age = age;} interface CheckAge {boolean test(Employee p); int age; public int getAge() { return 36; } static void printEmployees( List<Employee> m, CheckAge ca ){ for( Employee m1 : m ){ System.out.println( ca.test( m1 )); } } public static void main( String... argv ){ List<Employee> employees= new ArrayList<Employee>(); employees.add( new Employee( "Test", 29)); printEmployees( employees,new CheckAge() { public boolean test(Employee p) { return p.getAge() >= 18; p.getAge() <= 35;} }); } }
Lambda
The printEmployees method has an anonymous inner class and the screenshot shows
IntelliJ IDEA’s interpretation.
The product company I am working for is very far behind this type of technology curve and only technology evangelism might help.