Type-Import-on-Demand声明导入什么? [英] What does a Type-Import-on-Demand Declaration import?
问题描述
在Java中,有两种有效形式的 import
声明:
In Java, there are two valid forms of the import
declaration:
-
import java.lang.Math;
-
import java.lang.Math。*;
import java.lang.Math;
import java.lang.Math.*;
在后者中,使用通配符。此表单称为按需导入类型声明,但它与前者有何不同?它是否还导入 java.lang.Math
的子包?
In the latter, a wildcard is used. This form is known as a Type-Import-on-Demand declaration, but how is it different from the former? Does it also import the subpackages of java.lang.Math
?
如果数学怎么办?
是一个Type(例如,一个类)—是否会导入所有内部类?
What if Math
were a Type (e.g., a class)—would all of its inner classes be imported?
推荐答案
只导入直接嵌套的类型。声明不是递归的。
Only immediately-nested types are imported. The declaration is not recursive.
这适用于导入内部类的类型。这也适用于静态导入(用于导入方法)。
This does work with types for importing inner classes.This also works with static import (for importing methods).
import static a.b.c.FooBar.*;
这篇关于Type-Import-on-Demand声明导入什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!