Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't sub-packages see package private classes?

Okay so, I have this project structure:

package A.B

  • class SuperClass (this class is marked package private)

package A.B.C

  • class SubClass (inherits from super class)

I'd rather not make SuperClass publicly visible... It is really just a utility class for this specific project (A.B).

It seems to me that SubClass should be able to see SuperClass, because package A.B.C is a subpackage of A.B... but this is not the case.

What would be the best way to resolve this issue? I don't think it makes sense to move everything in A.B.C up to A.B or move A.B down to A.B.C... mainly because there will probably be an A.B.D which inherits from stuff in A.B as well...

I'm a bit new to Java, so be nice :D (I'm a C++ and .NET guy)

like image 893
Polaris878 Avatar asked Mar 21 '10 22:03

Polaris878


1 Answers

Packages are unique identifiers. You cannot make them follow the inheritance rules. Package and SubPackages are not analogical to Super and Sub classes.

I dont see any flaws in making the class that you wanted to use in the sub package to be visible to the outside world. I would be interested to know how this criterion is handled in C++/.net (as I am a java guy :) )

like image 92
bragboy Avatar answered Oct 21 '22 07:10

bragboy