JDK11新特性详解 增强局部变量类型推断var

1、增强局部变量类型推断var

Consumer consumer = t -> System.out.println(t.toUpperCase());
Consumer consumer = (var t) -> System.out.println(t.toUpperCase());

错误的形式:必须要有类型,可以加上var
Consumer consumer = (@Deprecated t) ->System.out.println(t.toUpperCase())
正确的形式
Consumer consumer = (@Deprecated var t) ->System.out.println(t.toUpperCase())

你可能感兴趣的:(JDK11新特性详解 增强局部变量类型推断var)