tags:

views:

78

answers:

2

I can declare the following package with modifiers but it doesn't seem to have any effect on anything:

private public protected static final package com.stackoverflow.mangodrunk

// ...
class Whatever {
    // ...
}  

So my question is, does adding a modifier before a package decleration do anything and why would it be allowed by the compiler?

Update: Seems to be an issue with the compiler bundled with Eclipse, as others have mentioned this is a compiler error using Sun's JDK.

+4  A: 

They're not. Which compiler are you using?

$ javac com/stackoverflow/mangodrunk/Whatever.java

com/stackoverflow/mangodrunk/Whatever.java:1: class, interface, or enum expected
private public protected static final package com.stackoverflow.mangodrunk;
                                      ^
1 error
Draemon
I'm using JDK 1.6.0_17, and you're correct, it has a compiler error when I try to compile it using javac. But under eclipse there is no problem.
mangoDrunk
What does that say about the Eclipse JDK?
duffymo
Probably a minor error in their grammar causing it to ignore *anything* before "package" not just comments? See if other keywords are ignored too. I guess you should report the bug unless it has been reported already.
Draemon
+3  A: 

According to the JLS, the only thing that can precede package is an annotation.

PackageDeclaration:
        Annotationsopt package PackageName ;

But an annotation looks like this (full grammar omitted for brevity):

NormalAnnotation:
        @ TypeName ( ElementValuePairsopt )

So your compiler should not be allowing standard access modifiers.

Source: http://java.sun.com/docs/books/jls/third_edition/html/packages.html

danben