java(下划线)是一个保留关键字
我刚刚将以下lambda表达式中的s
替换为_
:
s -> Integer.parseInt(s)
Eclipse编译器说:
'_' should not be used as an identifier, since it is a reserved keyword from source level 1.8 on.
我没有在JLS §3.9词汇结构/关键字中找到任何解释
你可以在下面搜索框中键入要查询的问题!
我刚刚将以下lambda表达式中的s
替换为_
:
s -> Integer.parseInt(s)
Eclipse编译器说:
'_' should not be used as an identifier, since it is a reserved keyword from source level 1.8 on.
我没有在JLS §3.9词汇结构/关键字中找到任何解释
# 1 楼答案
Java SE 9的Java语言更改 https://docs.oracle.com/javase/9/language/toc.htm#JSLAN-GUID-16A5183A-DC0D-4A96-B9D8-AAC9671222DD
从Java 9中,uu字符不能再用作标识符,而不仅仅是在lambda上下文中
# 2 楼答案
这是JEP 302的第2阶段,它将添加下划线作为特殊字符来表示lambda表达式中未使用的参数
# 3 楼答案
要看的地方是JLS §15.27.1. Lambda Parameters
因此,Eclipse消息具有误导性,特别是当为lambda参数生成错误或为任何其他
_
标识符生成警告时,这两种情况都使用相同的消息