The following is the definition of identifiers in Java
In most people’s understanding, Java identifiers The definition rules are as follows.
1. The identifier consists of letters, numbers, currency symbols (¥, $, etc.), and connection symbols (_, etc.). (The letters here are Unicode character sets, and are no longer limited to the traditional 26 English letters.)
2. The first character of the identifier can be a letter, currency symbol, or connection symbol, but it cannot be a number.
3. The identifier cannot be the same as the keyword in Java.
4. The identifier cannot be the same as the predefined literal constant name in Java (true, false, null).
(Recommended video: java video tutorial)
But sometimes when you use $ easily, you will have unexpected surprises. For example, the following code:
Creates an inner class xy in Ly's class
Then what? When running this class, something surprising happened after compilation. Two class files, Lyxy.class and Ly.class, were generated. If we were writing two class files, Ly xy.class and Ly.class, if we were writing Write two class files, Lyxy.class and Ly.class. If we are writing a Lyxy, will there be duplication of classes?
If you write according to the following method, there will be duplication of classes
What exactly Which category is repeated? You can refer to the above running results for analysis.
From the class file generated by the above running, it can be seen that Ly$xy.class will be repeated, so an error will be reported.
This article comes from php Chinese website, java tutorial column, welcome to learn!
The above is the detailed content of Analysis of the reasons why $ should not be used in Java classes. For more information, please follow other related articles on the PHP Chinese website!