Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

the number of class files in a java package constant

Tags:

java

I am new to java.My friend asked me this question today And i am looking for an answer to it. How to make the number of class files in a package, constant? i.e., even though one can access that package,they should not be able to add any new class to the exisiting package.

like image 234
user708479 Avatar asked Feb 24 '23 12:02

user708479


1 Answers

You want sealed packages. Once sealed, all classes from a package must come from the same JAR file. It basically boils down to adding the package to the manifest:

Name: myCompany/myPackage/
Sealed: true
  • See Sealing packages within a jar file
like image 121
mdma Avatar answered Mar 08 '23 10:03

mdma