简体   繁体   中英

Using Java's default package in Eclipse

In Eclipse, when I start a new Project, I go through the wizard, and when I get to writing my first class for that project I am asked to select a package. Sometimes out of laziness I just choose the default package.

The wizard warns me this is discouraged. Even if I ignore the warnings I never have any problems with the application due to this. Or at least, so far I have never had any problem.

So why does Eclipse want me to create a new package?

Eclipse, and most other IDEs, are geared towards large projects. Hobbyist programming and small-scale assignments can get by in IDEs often, but be aware that the general assumption would be for larger projects - anything between 10 and 5,000+ classes.

There is also a chance that you create a class which has a similar name to something in the Java API - for example:

Ambiguity in instantiating the class ( throw new MarshalException(); ) if both classes exist on the same classpath is a compilation error.

You actually can't import classes from the default package. I understand it's allowed as a convenience or for very small (one class file) tasks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM