0

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.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
srinik
  • 144
  • 1
  • 1
  • 10
  • 1
    why is everything kept public? why not just use private? – Aidanc Apr 28 '12 at 12:08
  • Actually it a very legacy code where i have to deprecate some functionality which is exposed to outside. I tried using @Deprecated but it doesn't stop people using it. – srinik Apr 28 '12 at 16:10

2 Answers2

1

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.

Kai Sternad
  • 22,214
  • 7
  • 47
  • 42
1

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.