_(下划线)是保留关键字 [英] _ (underscore) is a reserved keyword
问题描述
我刚刚在 _
中替换了以下lambda表达式中的 s
:
I've just replaced s
in the following lambda expression by _
:
s -> Integer.parseInt(s)
Eclipse编译器说:
Eclipse compiler says:
'_'不应该用作标识符,因为它是来自源级别1.8的保留关键字。
'_' should not be used as an identifier, since it is a reserved keyword from source level 1.8 on.
我没有在JLS§3.9词汇结构/关键词。
I haven't found any explanation in the JLS §3.9 Lexical Structure / Keywords.
推荐答案
要看的地方是< a href =http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.27.1>JLS§15.27.1。 Lambda参数
如果lambda参数的名称为_,则为编译时错误(即,单个下划线字符。)
不鼓励在任何上下文中使用变量名_。 Java编程语言的未来版本可以将此名称保留为关键字和/或赋予其特殊语义。
因此Eclipse消息具有误导性,特别是当两种情况都使用相同的消息时,为lambda参数生成错误,或者为任何其他 _
标识符生成警告。
So the Eclipse message is misleading, especially as the same message is used for both cases, when an error is generated for a lambda parameter or when a warning is generated for any other _
identifier.
这篇关于_(下划线)是保留关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!