Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package Access (Protected Modifier) in Java

Tags:

java

Suppose I have a package:

package com.g00gle.car

and

package com.g00gle.car.stereo

Is it possible to have a class in com.g00gle.car to access a class member in com.google.car.stereo? (Assuming that class member is labeled protected).

The answer is no... (by default) but is there a way to circumvent that? I have an application that I want to cut into distinct chunks... and to do that, I create extensions of the package. What's discouraging is the loss of package private access.


1 Answers

This need will be addressed in Java 7 with superpackages. Or at least it was going to be. Everything about Java 7 is currently up in the air.

  • JSR 294: Improved Modularity Support for the Java Programming Language

Edit

Thanks for the link from Peter Štibraný in the comments below. Mark Reinhold's blog indicates this has been moved to Java 8 for release sometime in 2012 (take both the release and the release date with a grain of salt).

like image 81
Mark Peters Avatar answered Apr 20 '26 19:04

Mark Peters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!