Package modifier produces error
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.
精彩评论