Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method on package level

Tags:

java

package

Is it possible to write a method that is available at package-level? Assume foo is a package:

long version = foo.getPackageVersion();
like image 335
Niklas R Avatar asked Dec 15 '22 20:12

Niklas R


1 Answers

No, it is not. Methods can only be defined on classes. Nowhere else.

A package is not physical, it can't serve as a container for byte code. Packages are nothing but namespaces for classes, enums and interfaces.

like image 64
Andreas Dolk Avatar answered Dec 28 '22 07:12

Andreas Dolk