Meaning of import statement in Java language

When we use the import statement in a java file, can anyone clearly explain to me what happened? If we add more and more Java classes, will it increase the file size? Why don't we use class loaders? What are the import restrictions?

Solution

The import declaration (not statement) is essentially a short-term enabler at the source level: it allows you to use a single identifier (such as list, min) to refer to a type or static member, rather than a fully qualified name (such as Java. Util. List, math. Min)

The import declaration part is a compile - time element of the source code, which does not exist at run time In JVM bytecode, the type name is always fully qualified. Unless you use a poorly written compiler, the binary file should contain only the name of the type actually used

Class loaders are used for completely different concepts, independent of the import function

JLS 7.5 Import Declarations

reference resources

> JLS 7.5. 1 Single-Type-Import Declaration > JLS 7.5. 2 Type-Import-on-Demand Declaration > JLS 7.5. 3 Single Static Import Declaration > JLS 7.5. 4 Static-Import-on-Demand Declaration

You can also have a look

> Java Tutorials/Using package members > Java Language Guide/static import

Various import related issues

About the grammatical function of import:

> What is an import called? – This is a statement, not a statement

On demand point to point single type:

> Import package.* vs import package. SpecificType > Why is using a wild card with a Java import statement bad? > What’s the difference between import java. util.*; and import java. util. Date;?

Import static:

> What does the static modifier after import mean? > @ L_ 502_ 13@ > Should I use static import?

Performance related issues:

> Does importing of packages change visibility of classes? – Absolutely not! > Do multiple import statements in a program affect performance? – NOPE! > Any reason to clean up unused imports in Java,other than reducing clutter?

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>