Java compulsory packaging declaration

In java, why is it mandatory for each class to declare the package to which it belongs. I mean, the hierachy package has already been described / applied using the file system structure folder. It seems to me that the line:

package com.mypackage;

As the first line of each class is somehow redundant information. But I'm sure there is a good reason for him to be there.

+4
source share
1 answer

I mean, the package hierarchy is already described / applied using the file system folder structure.

Not necessary. While it is certainly a good idea to organize your code this way, it is not a requirement. Also keep in mind that the source code does not have to be on the file system.

, . , , - , , ( JLS), .

+3

All Articles