Why shouldn't we use the (default)src package?

后端 未结 6 1269
感情败类
感情败类 2020-12-21 08:08

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

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-21 08:47

    Originally, it was intended as a means to ensure there were no clashes between different pieces of Java code.

    Because Java was meant to be run anywhere, and over the net (meaning it might pick up bits from Sun, IBM or even Joe Bloggs and the Dodgy Software Company Pty Ltd), the fact that I owned paxdiablo.com (I don't actually but let's pretend I do for the sake of this answer) meant that it would be safe to call all my code com.paxdiablo.blah.blah.blah and that wouldn't interfere with anyone else, unless they were mentally deficient in some way and used my namespace :-)

    From chapter 7, "Packages", of the Java Language Spec:

    Programs are organized as sets of packages. Each package has its own set of names for types, which helps to prevent name conflicts.

    I actually usually start by using the default package and only move it into a real package (something fairly easy to do with the Eclipse IDE) if it survives long enough to be released to the wild.

提交回复
热议问题