Instantly share code, notes, and snippets.

Embed
What would you like to do?
Warning when _ used as an identifier in Java 8. Compilation error in Java 9 (though, bytecode from Java 8 is executed).
alexandre ~/keyword $ /usr/lib/jvm/java-8-oracle/bin/javac Keyword.java
Keyword.java:3: warning: '_' used as an identifier
int _ = 1;
^
(use of '_' as an identifier might not be supported in releases after Java SE 8)
Keyword.java:4: warning: '_' used as an identifier
System.out.println(_);
^
(use of '_' as an identifier might not be supported in releases after Java SE 8)
2 warnings
alexandre ~/keyword $ /usr/lib/jvm/java-8-oracle/bin/java Keyword
1
alexandre ~/keyword $ /usr/lib/jvm/java-9-oracle/bin/java Keyword
1
alexandre ~/keyword $ /usr/lib/jvm/java-9-oracle/bin/javac Keyword.java
Keyword.java:3: error: as of release 9, '_' is a keyword, and may not be used as an identifier
int _ = 1;
^
Keyword.java:4: error: as of release 9, '_' is a keyword, and may not be used as an identifier
System.out.println(_);
^
2 errors
public class Keyword {
public static void main(String[] args) {
int _ = 1;
System.out.println(_);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment