JDK-6424492 : Make Package objects consistent and expose through Java language
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version: 5.0
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-05-11
  • Updated: 2011-02-16
  • Resolved: 2008-04-25
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE REQUEST :
You should be able to get a Package object for any class.  You should also be able to specify Package objects as constants (available to annotations) through syntax like "com.mypackage.MyClass.class.package" or "com.mypackage.package".

JUSTIFICATION :
The ability to specify packages would allow annotations to specify packages.  In particular, I would like to see a feature like @VisibleTo((Class|Package)+) and @VisibleToSubPackagesOf(Package+) as ways of sharing default access classes and members with other classes and packages (without making them public or protected).  This would very neatly solve a problem that we've had since the beginning.  I've been thinking about this problem for the last 9 years or so and this is the best idea I've come up with because it is Java simple.  I hope we can fix this serious lacking simply like this...

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Ability to reference Package objects easily through the Java language and through annotations.
ACTUAL -
Feature does not exist.

CUSTOMER SUBMITTED WORKAROUND :
No easy workaround.  Package objects are not consistently available for classes and there is no way to access them directly in the language or through annotations.  The @VisibleTo*() annotations I'd like to see are not possible at all right now.

Comments
EVALUATION This RFE is rather confused. Getting a Package object via an expression of the form <package name>.package is not a bad idea, but I don't immediately see how it allows the annotations of interest to the submitter. The ability to write and read annotations on packages is available through package-info.java and Package#getAnnotations. Whether those annotations should describe accessibility is another matter entirely, and is within the scope of JSR 277. Returning to the <package name>.package expression form itself: it's not worth doing in isolation but could be considered alongside method and field literals (5043025).
06-11-2006