[ACCEPTED]-Making package-protected java class visible in parent package-java

Accepted answer
Score: 54

As far as I'm aware, it's not possible. While 2 we tend to think of packages as forming a hierarchy, they 1 don't as far as the Java language is concerned.

Score: 31

As stated in all the other answers: No. The 37 package hierarchy means nothing outside 36 of the mind of the person who set it up.

In 35 my opinion this is Java's major flaw. When 34 building up monster systems by merging together 33 other monster programs, nothing beats Java-the-language. All 32 other languages eventually end up in confused, undocumentable, indecipherable 31 piles of code.

Well, so does Java, but it 30 gets a lot further than any other language 29 I've used. But its ignorance of package 28 hierarchy--the inability to encapsulate 27 data in a package hierarchy--is the limitation, or 26 brick wall, that stops it. I can put a 25 system, or set of classes that work together, in 24 a single package. Then I can make a bunch 23 of those classes package private so that 22 when this package is added to another super-system 21 that super-system cannot see--and be confused 20 by--those hidden classes.

But if my system is 19 already super enough ("super" as in "superman", not 18 "superclass") to need several packages for 17 clarity, my formerly package-private classes 16 must now be public, and I can't stop the 15 super-super-system from seeing everything 14 in my super-system.

To make a vast, complex 13 system work, the complexity at every point 12 must be minimized. My super-system has 11 to look as simple as possible to the super-super-system 10 I'm adding it to. Having all the pipes 9 and wires and beams and welds sitting out 8 in public display because I cannot make 7 them package-level-private does not help 6 this.

I hope Jigsaw, mentioned elsewhere, will 5 help. I also hope developer tools such 4 as IDEs will start displaying packages in 3 an outline format rather than treating a.b 2 and a.b.c.d.e as if they were all on the 1 same level--just elements in the same list.

Score: 7

Currently, this is not possible. Java packages 8 are not really hierarchical in nature - classes 7 are either in the same package or they are 6 not.

However, this is likely one of the things 5 that will be addressed by Project Jigsaw, which may be 4 included in Java 8. That should allow creating 3 classes which are public within all the 2 packages of a module, but are not exported 1 to other modules.

Score: 4

No, it is not possible. Package visibility 6 cannot selectively extend to other packages. A 5 class may only be private (that is, visible 4 only to a non-private enclosing class), package-private 3 (no modifier, visible to only to other classes 2 in the same package), or public (visible 1 to all classes).

Score: 4

As far as i know it is not possible in Java. For 2 more information see the link here which explains 1 the access modifiers in Java clearly.

More Related questions