If Java does not have a preprocessor, what is “import”

This article is in 2.2 1 says that there are no more typedef, definitions or preprocessor In C, include is part of the preprocessor What is import?

Solution

Import although the name doesn't "import" anything, it just lets you call a class without a fully qualified name

For clarity, if I execute the import Java util. ArrayList;, Now I can call the ArrayList class ArrayList If I don't, I can still use this class. I just need to call it Java util. ArrayList.

If you import the whole package with *, the worst thing is that there is a name conflict. Therefore, you must use the full name to refer to the Java class, but it will not use more memory at run time

java. Classes in Lang are automatically imported

Java 1.5 introduces static imports, which enables programmers to reference imported static members as if they were declared in the class using them They should be used with caution The acceptable usage is to import the JUnit assert method For example, traditional import:

import org.junit.Assert;
...
Assert.assertEquals(expected,actual);

Use static import:

import static org.junit.Assert.assertEquals;
...
assertEquals(expected,actual);
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
分享
二维码
< <上一篇
下一篇>>