Why shouldn#39;t we use the (default)src package?(为什么我们不应该使用(默认)src 包?)
问题描述
我最近开始使用 Eclipse IDE,并在许多地方阅读了不应使用默认 (src) 包并创建新包的地方.
我只是想知道这背后的原因.
I recently started using Eclipse IDE and have read at a number of places that one shouldn't use the default(src) package and create new packages.
I just wanted to know the reason behind this.
推荐答案
使用默认包可能会造成命名空间冲突.假设您正在创建一个包含 MyClass
类的库.有人在他的项目中使用你的库,并且在他的默认包中也有一个 MyClass
类.编译器应该做什么?Java 中的包实际上是一个完全标识您的项目的名称空间.所以在现实世界的项目中不要使用默认包是很重要的.
Using the default package may create namespace collisions. Imagine you're creating a library which contains a MyClass
class. Someone uses your library in his project and also has a MyClass
class in his default package. What should the compiler do? Package in Java is actually a namespace which fully identifies your project. So it's important to not use the default package in the real world projects.
这篇关于为什么我们不应该使用(默认)src 包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么我们不应该使用(默认)src 包?


- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01