为什么我们不应该使用(默认)src 包?

编程入门 行业动态 更新时间:2024-10-12 01:23:05
本文介绍了为什么我们不应该使用(默认)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 包?

本文发布于:2023-11-03 21:32:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1556132.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:src

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!