srinik
srinik

Reputation: 144

How to create a restricted package like sun.misc*

I am developing a library which is consumed by other teams, in the library there are some classes/methods which are public but i don't want others to use them.

Some thing like what sun.misc package is in java, in this though all the classes are public the compiler throws "restriction error" while using it.

Upvotes: 0

Views: 272

Answers (2)

user784540
user784540

Reputation:

I am not aware that making a class in sun.misc package may prevent someone from accessing its public methods. Just checked it and I can access sun.misc.MyCustomClass methods.

I think it is a sign of bad architecture when you have public methods but don't want someone to use them.

Upvotes: 1

Kai Sternad
Kai Sternad

Reputation: 22850

One way you can do this is by applying Aspect Oriented Programming (AOP). Restricting access is a typical crosscutting concern that is a good match for AOP.

Upvotes: 1

Related Questions