我正在尝试了解 Java docs 中提到的缺点
安全限制
Reflection requires a runtime permission which may not be present when running under a security manager.
反射需要哪些运行时权限?在这种情况下,安全管理器是什么?这个缺点只是 Applet 特有的吗?
内部暴露
Since reflection allows code to perform operations that would be illegal in non-reflective code, such as accessing private fields and methods, the use of reflection can result in unexpected side-effects, which may render code dysfunctional and may destroy portability. Reflective code breaks abstractions and therefore may change behavior with upgrades of the platform.
反射如何打破抽象?以及它对平台升级有何影响。
请帮我澄清这些。非常感谢。
最佳答案
首先,您应该始终问自己为什么要在代码中进行反射。不经过反射(reflection)就不能进行操作吗?如果是,那么只有您应该使用反射。反射使用有关类、变量和方法的元信息,这会增加开销、性能问题和安全威胁。
要详细了解反射的缺点,请访问 http://modernpathshala.com/Forum/Thread/Interview/310/what-are-the-drawbacks-of-reflection
关于java - 了解 Java 反射的缺点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22132804/