开发者

Package modifier produces error

开发者 https://www.devze.com 2023-03-20 03:34 出处:网络
Eclipse is giving me an error when defining a top level class with the package modifier, the error is :

Eclipse is giving me an error when defining a top level class with the package modifier, the error is :

syntax error on token "package", delete this token.

My code is simpy:

package class MyClass { ... }

My google-foo seems to be broken, any help would be great! Please ask any question开发者_Go百科s necessary...

Thanks!


When you want to delcare a class as package private, you should omit the modifier. The package keyword is used to define packages.


You can't do that. It's simply not valid Java - because package isn't a modifier.

You declare a package with the package keyword; you declare a class with the class keyword:

package foo;

class Bar
{
}

If you're trying to explicitly specify the default "package level" accessibility, that (unfortunately IMO) can't be specified explicitly. Just leave all access modifiers off.

0

精彩评论

暂无评论...
验证码 换一张
取 消