Hacker News new | ask | show | jobs
by mohaine 3278 days ago
In Java, private/protected functions/fields are mostly only a compile time check. Your code will not compile with if they shouldn't be able to see the function/field. But java also has a runtime inspection framework that allows you to view and call these scope hidden functions/fields in contexts that should not be allowed. You do have to ask nicely though with an extra call to request access. This is heavily used in things like Json/XML parsers and ORM tools. Really anyplace you need to blindly reconstruct an object programmatically.
1 comments

> In Java, private/protected functions/fields are mostly only a compile time check.

Indeed, with reflection you can mutate member properties... I taught myself [this trick](https://stackoverflow.com/questions/10638826/java-reflection...) right away. You can also disable reflection via security policy, which would forbid that access with an exception.