为什么Java没有“深度”通配符导入? [英] why doesn't Java have "deep" wildcard import?

查看:96
本文介绍了为什么Java没有“深度”通配符导入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么不导入one.two。* include import one.two.three.MyClass
Java不应该像那样导入one.two。** ?或者是否有任何理由(除了他们没有做到,不是他们不能这样做)?

Why doesn't import one.two.* include import one.two.three.MyClass? Shouldn't Java have something like import one.two.**? Or is there any reason (other than they just didn't do, not that they couldn't do it)?

谢谢

推荐答案

Java不会将包视为真正的子类化;而 java.util java.util.concurrency 可能看起来像第二个是第一个的一部分,它们是处理完全独立,点大部分都是为了整洁。

Java does not treat packages as truly subclassing each other; while java.util and java.util.concurrency might look like the second is somehow part of the first, they are treated as entirely independent and the dot is mostly there for neatness.

这意味着你不必害怕命名你的类或接口与声明的另一个相同在以后的一些超级或子包装中,这也意味着你应该只写几个额外的进口线。

This means you don't need to be afraid of naming your class or interface the same as another one declared in some super- or sub-package on a later date, and it also means you should really just write a couple extra lines of imports.

这个决定背后的原因,正如Peter Lawrey解释的那样,源于Java对简单性的普遍倾向。最佳做法通常是永远不要使用导入通配符。

The reasons behind this decision, as Peter Lawrey explained, stem from Java's general lean towards simplicity. Best practice is often to never use import wildcards at all anyway.

这篇关于为什么Java没有“深度”通配符导入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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