4 Replies Latest reply: Jun 1, 2010 7:44 PM by jschellSomeoneStoleMyAlias RSS

    compiler ignores any modifier specified just before package declaration

    843810
      Hi,
      I was going through Java Language Specifiation 2nd edition and found this:

      A package declaration in a compilation unit specifies the name (§6.2) of the package to which the compilation unit belongs.

      PackageDeclaration:
      package PackageName ;

      Later, out of curiosity I tried something like this:
      private package somepackage;
      
      public class SomeClass {
      
      }
      I was expecting a compile time error because of writting private just before package declaration but I was suprised when I didn't get one. On the other hand the other classes which were importing (using) this SomeClass were compiled without any compile time error.

      Then I decided to run it, but I didn't get any error on running them which though makes sense as even I was not expecting them to throw any error on execution.

      So any idea why Java compiler simply ignores this modifier for package declaration. I mean it doesn't seems to cause any change in the visibilty of the class then why is it even permitted. Is it a bug in Java compiler or am I missing something?

      Thanks and Regards,
      Sachin.