Java 9 changes the characteristics of the Java language, and removing the underscore from the legal name is a major change made by Oracle.
Using underscore as variable name in Java 8
Although it is supported in Java 8, if you use _ as an identifier, a mandatory warning will be issued, telling you that "the use of ‘_’ as an identifier may not be supported in versions after Java SE 8." (Refer to JDK-8005852 to treat ‘_’ as an identifier)
// Java program to illustrate // using underscore as // variable name class UnderScore_works { public static void main(String args[]) { int _ = 10; System.out.println(_); } }
Output:
10
Using underscore as variable name in Java 9
In Java 9, underscore as variable name won’t work altogether. Below source code can no longer be compiled.
// Java program to illustrate // using underscore as // variable name in java 9 class UnderScore_dont_works { public static void main(String args[]) { int _ = 10; System.out.println(_); } }
Important points:
Australia
UK
UAE
Singapore
Canada
New
Zealand
Malaysia
USA
India
South
Africa
Ireland
Saudi
Arab
Qatar
Kuwait
Hongkong
Copyright 2016-2023 www.programmingshark.com - All Rights Reserved.
Disclaimer : Any type of help and guidance service given by us is just for reference purpose. We never ask any of our clients to submit our solution guide as it is, anywhere.