简体   繁体   English

*在java.io. *中的用途是什么

[英]What is the purpose of * in java.io.*

What is the purpose of the * in java.io.*? java.io. *中*的目的是什么?

import java.io.*;
class Trial{
     public static void main(String[]args){
         System.out.println("Hello,World!");
     }
}

The * tells the compiler to import all top-level classes in java.io on demand. *告诉编译器按需导入java.io所有顶级类。 The construct is called a type-import-on-demand declaration. 该构造称为按需类型导入声明。

From JLS §7.5.2 : JLS§7.5.2开始

A type-import-on-demand declaration allows all accessible types of a named package or type to be imported as needed. 按需类型导入声明允许根据需要导入命名包或类型的所有可访问类型。

\nTypeImportOnDemandDeclaration: TypeImportOnDemandDeclaration:\n    import PackageOrTypeName . 导入PackageOrTypeName。 * ; *;\n

So, for example, since you've included that import statement, you can use a class like java.io.File without having to prefix the type name with java.io ; 因此,例如,由于包含了该import语句,因此可以使用java.io.File类的类,而不必在类型名称前加上java.io ; you can use the simple name File . 您可以使用简单的名称File

星号表示应该导入java.io包中的所有类。

A wildcard in a package name import is used to include all the classes contained in that specific package. 软件包名称import通配符用于包括该特定软件包中包含的所有类。 Check official documentation . 检查官方文档

In addition you are able to import inner static classes to be able to refer to them without a fully qualified name, eg: 此外,您还可以导入内部静态类,以便能够在不使用完全限定名称的情况下引用它们,例如:

import org.package.MyClass;

//MyClass.InnerClass inner; not needed
InnerClass inner;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM