本文介绍了为什么修改器允许包装似乎没有做任何事情?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用修饰符声明以下包,但对任何内容似乎没有任何影响:

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?

更新:似乎是与Eclipse捆绑在一起的编译器的问题,其他人也提到这是使用Sun的JDK的编译器错误。 / p>

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.

推荐答案

他们不是。你使用哪个编译器?

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

这篇关于为什么修改器允许包装似乎没有做任何事情?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 21:01