使用默认包可能会创建命名空间冲突。假设您正在创建一个包含 MyClass 类的库。有人在他的项目中使用你的库,并且在他的默认包中也有一个 MyClass 类。编译器应该做什么? Java中的包实际上是一个完全标识您的项目的命名空间。所以重要的是不要在现实世界的项目中使用默认包。
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.
解决方案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包?
发布评论