For convenience, the Java compiler automatically imports two entire
packages for each source file: (1) the java.lang package and (2) the
current package (the package for the current file).
IDE不会导入您的所有包,因为1
您可能不需要它们,为什么要导入它们李>
更重要的是,您可以在不同的包中使用相同名称的类,这将导致名称歧义李>
If a member in one package shares its name with a member in another
package and both packages are imported, you must refer to each member
by its qualified name. For example, the graphics package defined a
class named Rectangle. The java.awt package also contains a Rectangle
class. If both graphics and java.awt have been imported, the following
is ambiguous.
# 1 楼答案
首先,在Eclipse中,可以使用Ctrl-SHIFT-O自动导入所需的任何内容
从java package tutorial开始:
IDE不会导入您的所有包,因为1
这将导致不必要的头痛,确保您始终参考正确的软件包。通过自己导入包和类,您可以确保始终使用要导入的特定类
# 2 楼答案
这是我的想法。这样想,
假设在不同的包中有两个同名的类,那么IDE如何解析包导入?它如何知道要导入哪个SendFormAction? 因此,通常IDE为您提供了导入包的选项[EclipseIDE中的cntrl+shift+O] 如果有混淆,它会询问您要导入哪一个
# 3 楼答案
因为有时不同的类具有相同的“短”名称,所以IDE不知道您指的是哪一个。例如,如果将粘贴代码复制到包含
Date
的IDE中,它不知道您的意思是java.sql.Date
还是java.util.Date
。在这些情况下,IDE将允许您从所有可用的具有该名称的类中进行选择