Usage of Underscore(_) in Java 8 and Java 9

Using underscore (_) as a variable name was normal till Java 7. But now its usage will either result in a warning or even compilation error depending upon your Java version. Imagine this code:

int _ = 10;
function someFunc(String _){

This piece of code would have worked fine prior to Java 8. But in Java 8 you will be prompted with this warning:

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

As guessed correctly, in Java 9 this line will be reported as a compilation error.

In Java 10 underscore character is being rehabilitated to indicate unused lambda parameters. That is why Java first deprecated it in version 8 and retired it in version 9.

So if you are using underscore variable name anywhere in your code, start getting rid of it 🙂

Mar Java Mit Java 🙂

Uday Ogra

Connect with me at and lets have some healthy discussion :)

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *