在 Lambda 开发邮件列表中,Lambda 语法引发了新一轮的讨论,与以往不同的是,这次以收集意见为主。
“Strawman”语法提供了一套临时性的方案,意在讨论该语法的可行性以及一些细节差异,这些细节包括 Lambda 表达式与类型推断如何在 Java 下工作等,同时该方案不会作为永久性的语法解决方案。目前,被推荐的 4 种语法形式如下所示:
- Strawman型:
#(arglist)(expr)
and#(arglist){statements}
- BGGA型:
{ args -> statements }
- SotL型:
#{ args -> statements}
- Redmond型:
(args) -> { statements }
该调查还分别附带了相应的代码片段:
Example of Strawman: list.filter( #(Foo t)(t.length() > 3) ) .map( #(Foo t)(t.barCount) ) .max(); Example of BGGA: list.filter( { Foo t -> t.length() > 3 } ) .map( { Foo t -> t.barCount } ) .max(); Example of SotL: list.filter(#{ Foo t -> t.length() > 3 } ) .map(#{ Foo t -> t.barCount } ) .max(); Example of Redmond: list.filter((Foo t) -> { t.length() > 3 } ) .map((Foo t) -> { t.barCount } ) .max();
关于提案的更多细节可参看 Lambda 开发邮件列表中的原文,从中还可了解到如何反馈调查结果等信息。
查看英文原文: Lambda Syntax Survey
评论