Dr. Noorul Hameed, B.Sc., M.C.A, PhD (USM)
Senior IT Engineer
Noorul Hameed wrote: In JDK 9, use of _ (underscore) as an identifier causes an compile-time error.
In the following line // t(_ -> 0); //line 1, it will be occurred an error while it is uncommented.
Dr. Noorul Hameed, B.Sc., M.C.A, PhD (USM)
Senior IT Engineer
Co-Author of OCP Java SE 8 Programmer II Exam Guide
Stephan van Hulst wrote:I couldn't find any hints of the kind.
Just a hint.That JLS section wrote:The use of the variable name _ in any context is discouraged. Future versions of the Java programming language may reserve this name as a keyword and/or give it special semantics.
Campbell Ritchie wrote:Maybe; that might be what is hinted at in the Java8 JLS link I posted.
Stephan van Hulst wrote:I couldn't find any hints of the kind.
Good catch , but the second link I posted, this one, is to the Java8 JLS. The Java9/10 equivalent pages include this:-Ahmed Ibrahim wrote:. . . The link you've posted is Java10 JLS not Java8 JLS . . .
JLS §15.27.1 wrote: In Java SE 8, the use of _ as the name of a lambda parameter was forbidden, and its use discouraged as the name for other kinds of variable (§4.12.3). As of Java SE 9, _ is a keyword (§3.9) so it cannot be used as a variable name in any context.
Campbell Ritchie wrote:
the second link I posted, this one, is to the Java8 JLS
Stephan van Hulst wrote:I think the reason is that in many functional languages, underscore is used to indicate that you don't care about the value of a certain parameter because you're not going to use it. Maybe the Java designers wanted to keep this option open until they decided what they really wanted to do, so they prevented people from using it as an identifier so they don't have to worry about backwards compatibility.
Maybe in the future they will allow the use of underscore as a parameter name in lambda expressions, while prohibiting their use in lambda expression bodies, thereby enforcing the convention that underscores indicate the parameter is not used.
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |