Home > Java > JavaBase > body text

Analysis of the reasons why $ should not be used in Java classes

angryTom
Release: 2019-11-30 14:43:59
forward
2819 people have browsed it

Analysis of the reasons why $ should not be used in Java classes

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?

Analysis of the reasons why $ should not be used in Java classes

Analysis of the reasons why $ should not be used in Java 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.

Analysis of the reasons why $ should not be used in Java classes

Analysis of the reasons why $ should not be used in Java classes

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template