Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are modifiers allowed for a package when they don't seem to do anything?

Tags:

java

eclipse

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.

like image 519
Turing Avatar asked Jan 24 '10 15:01

Turing


1 Answers

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
like image 107
Draemon Avatar answered Oct 18 '22 15:10

Draemon