星型导入是否包含Java中的子包? [英] Does the star import include subpackages in Java?

查看:90
本文介绍了星型导入是否包含Java中的子包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您声明这样的导入时:

When you declare an import like this:

import com.microsoft.azure.storage.*;

这包括其子包中的所有内容吗?例如,它是否包含此内容?

Does that include everything in its subpackages too? For example, does it include this?

import com.microsoft.azure.storage.blob.*

如果没有,为什么不呢? (编辑:为什么问题基本上是偏离主题。在考虑正确答案时忽略该位。)

If not, why not? ( the "why" question is basically off topic. ignoring that bit when considering a correct answer.)

推荐答案

没有它才不是。它只导入包中的所有内容(即目录本身)。子目录被认为是不同的包,因此您需要:

No it does not. It only imports everything in the package (i.e. the directory itself). Sub-directories are considered to be different packages, so you would need to:

import com.microsoft.azure.storage.*
import com.microsoft.azure.storage.blob.*

至于为什么语言设计师选择走这条路,人们只能猜测,但他们决定采用的系统确实允许更细粒度的方法。

As to why the language designers chose to go this route, one can only guess, but the system that they decided to go with does allow for a more fine-grained approach.

这篇关于星型导入是否包含Java中的子包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆