4

Why do I get "as of release 9, '_' is a keyword, and may not be used as an identifier" error when using a single underscore variable name?

This happens when compiling Java code with javac version 8.

Randy Sugianto 'Yuku'
  • 71,383
  • 57
  • 178
  • 228
  • 3
    See http://stackoverflow.com/questions/23523946/underscore-is-a-reserved-keyword/23525446 – Alexis C. Feb 09 '15 at 16:53
  • Works perfectly fine for me. What is the exact version you're using? And IDE or just command line? – Rohit Jain Feb 09 '15 at 16:53
  • Because it is going to be a reserved keyword? For what purposes? – Randy Sugianto 'Yuku' Feb 09 '15 at 16:54
  • 2
    @yuku If you are familiar with Scala, the underscore is used for various cases such as an anonymous function placeholder (see example above). Maybe in a future release we will be able to do something along the lines of `Stream.of(1, 2, 3).map( _ + 2)` which would result in a Stream of 3, 4, 5. Since it's not very common to use only an underscore as an identifier, I think it's fair to prevent that it will have a special meaning in the future releases. – Alexis C. Feb 09 '15 at 16:59
  • 3
    @ZouZou: [It won’t be like Scala](http://mail.openjdk.java.net/pipermail/lambda-dev/2013-July/010670.html) or well, let’s call it unlikely (never say never). – Holger Feb 09 '15 at 18:50

0 Answers0