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

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!

Statement
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools