0

I have a application where users can write their customizations using the exposed public APIs. There are few public classes and API that are public but we don't want them to be accessible in the customization code for the users. Is there any way in java to do this without changing the access modifiers of the remaining APIs. I am exploring java security manager, don't know if it would work, any help would be appreciated.

  • 1
    whitout any explanation on how you expose the API and classes, it is hardly answerable – jhamon Feb 15 '22 at 14:16
  • https://www.javatpoint.com/access-modifiers – Robert Harvey Feb 15 '22 at 14:17
  • In particular, *"**Default:** The access level of a default modifier is only within the package. It cannot be accessed from outside the package. If you do not specify any access level, it will be the default."* – Robert Harvey Feb 15 '22 at 14:17
  • The answer to "Is there any way in java to do this without changing the access modifiers of the remaining APIs" is "No." – Robert Harvey Feb 15 '22 at 14:18
  • And even using access modifiers is no guarantee, given the existence of reflection. But it doesn't matter; "package private" is good enough for most purposes. Bite the bullet and use proper access modifiers. – Robert Harvey Feb 15 '22 at 14:19
  • Modules could help. Packages not exported are not accessible by other modules. – Johannes Kuhn Feb 15 '22 at 16:02

0 Answers0