JSR-294 Superpackages

Discussions

Blogs: JSR-294 Superpackages

  1. JSR-294 Superpackages (1 messages)

    In reference to an article named : The Open Road: Superpackages which address superpackages or JSR-294 in great detail, David Linsin blogs about his impressions on the subject.
    Java's package mechanism today, is basically broken, because there is no hierarchical model. Hence, there is no way to completely hide your implementation from the outside world and no true separation of interfaces and implementation. One could argue that you could mark your methods "private" or "package private", but you will be running into situations - sooner or later - where you want them to be accessible not only within the same package, but also from subpackages of their hierarchy. JSR 294 is trying to address this problem. The idea is to create a superpackage around a set of packages, which are called "members". Those members contain classes, so called "exports", which define access points to the superpackage from outside world. The most compelling advantage of this JSR, is fact that access to members are restricted by the compiler. You will get a compile time error, if you try to use classes of a superpackage, which are not exported. Unfortunately there is no way to restrict access to methods, which would come in handy.
    Read David's complete post: http://dlinsin.blogspot.com/2008/03/jsr-294-superpackages.html Read the base article on superpackages: http://today.java.net/pub/a/today/2008/03/06/jsr-294-superpackages.html
  2. I would like to have something like this: --file Aaa.java package com.example.demo; superpackage {"s1", "s2", "s3"}; public class Aaa { visibility{"s1", "s2"} void xxx() {} } --file Bbb.java package com.example.demo; superpackage {"s2"}; visibility {"s2"} class Bbb { public static doit() { Aaa a = new Aaa(); a.xxx(); } } --file Ccc.java package com.example.demo; superpackage {"s3"}; public class Ccc { public static main(String[] args) { Aaa a = new Aaa(); a.xxx(); ---> compiler error, class Ccc doesn't see the xxx method Bbb.doit(); ---> compiler error, class Ccc doesn't see class Bbb } }