Are private methods really safe?

后端 未结 7 1533
旧巷少年郎
旧巷少年郎 2021-01-30 15:26

In Java the private access modifier consider as safe since it is not visible outside of the class. Then outside world doesn\'t know about that method either.

相关标签:
7条回答
  • 2021-01-30 16:19

    private is not for security, it is to keep the code clean and to prevent mistakes. It allows users to modularize the code (and how it is developed) without having to worry about all the details of the other modules

    Once you release your code, people can figure out how it works. There's no way to "hide" the logic if you eventually want the code to run on a computer. Even compiling to binary is jsut a level of obfuscation.

    So, there's no way that you can set up your API to do special things that you don't want others to be able to call. In the case of a web API, you could put the methods you want control over on the server side.

    0 讨论(0)
提交回复
热议问题