比较扩展/实现的静态寻址和导入
使用之间有什么区别吗?
public ClassName extends some.package.Class implements another.package.Interface {}
使用和
import some.package.Class;
import another.package.Interface;
public ClassName extends Class implements Interface {}
在谈论性能、兼容性等方面,
Is there any difference between using
public ClassName extends some.package.Class implements another.package.Interface {}
and
import some.package.Class;
import another.package.Interface;
public ClassName extends Class implements Interface {}
when talking about performance, compatibility, etc..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有什么区别。字节码是相同的。所有这些都发生在编译时,对性能的影响为零。您应该仅根据您对可读性的评估来做出此决定。
There is no difference. The byte code is identical. All this happens at compile time, there is zero performance impact. You should make this decision based solely on your evaluation of readability.
这是一个编译时功能,因此与性能无关。从兼容性的角度来看,唯一的想法是,如果您有 2 个包含名为
Entity
的类的包,并且有一个模块您想使用它们,并且具有import ... 表示只有这些实体之一可以使用其非限定名称。但这更多的是为了维护而不是为了兼容性。
It's a compile-time feature, so it's related to performance by no means. From compatibility standpoint, the only idea is that if you have 2 packages with classes named
Entity
and there's a module where you'd like to use both of them, havingimport ...
means only one of these entities would be available using it's unqualified name. But it's more to maintenance than to compatibility.