java - 了解 Java 反射的缺点

标签 java reflection

我正在尝试了解 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/

相关文章:

objective-c - 使用反射的属性类型或类

java - 从类名创建类实例

java - 如何在 Android 上创建和/或附加到文件?

java - 业务对象中的应用程序上下文

java - Spring Boot with websphere 8.5.5 - UOWManager 事务处理失败

java - 如何编写一个按键监听器来跟踪 Java 中的所有击键?

c# - 系统.反射

java - "If statement"连续检查for循环索引数的倍数

reflection - 如何用threejs实现逼真反射

java - 如何复制 java.lang.reflect.Method?