Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

_ (underscore) is a reserved keyword

I've just replaced s in the following lambda expression by _:

s -> Integer.parseInt(s)

Eclipse compiler says:

'_' should not be used as an identifier, since it is a reserved keyword from source level 1.8 on.

I haven't found any explanation in the JLS §3.9 Lexical Structure / Keywords.

Answer*

Draft saved
Draft discarded
Cancel
12
  • 27
    Note that as of Java 9, _ will be disallowed as any legal identifier names and not only as a lambda parameter name. This was actually fixed in build 43 : bugs.openjdk.java.net/browse/JDK-8061549 Commented Jul 9, 2015 at 22:14
  • 4
    @lscoughlin: Isn’t "Future versions of the Java programming language may reserve this name as a keyword and/or give it special semantics" statement enough? Well, replace "may reserve" by "will use", and you’ll get the picture. Maybe this mail reference helps... Commented Jul 27, 2015 at 12:57
  • 11
    What is this? Java breaking backwards compatibility? Commented Jul 27, 2015 at 17:44
  • 11
    @Arturo Torres Sánchez: that’s nothing new. There were times when enum and assert were legal identifiers... Commented Jul 27, 2015 at 17:52
  • 12
    @Holger actually there are tons of languages that use underscore as a name placeholder (Scala, Clojure, F#, SML, Erlang, just to name a few). It's an established pattern that traces back to 90s or 80s, I believe, so disobeying it is odd. Commented Jul 28, 2015 at 20:59

lang-java

AltStyle によって変換されたページ (->オリジナル) /