EJB 中是否允许反射?

Is Reflection allowed within EJBs?

我想知道,反射的哪些部分允许在 EJB 中使用 (EJB3.x),哪些不鼓励使用,哪些禁止使用。

[编辑] 我通常是在谈论不同 EJB 类型上的 getMethod()、method.invoke() 等内容,所以没有 java POJO 内容。

我搜索了 EJB 核心规范,但没有找到真正的提示。

我个人认为,避免在框架外使用反射是一种很好的编程风格,但问题仍然存在,哪些部分是标准允许的?

提前致谢!

您是否看到规范 EJB 3.1 在第 21.2.2 点中所说的内容?

The enterprise bean must not attempt to query a class to obtain information about the declared members that are not otherwise accessible to the enterprise bean because of the security rules of the Java language. The enterprise bean must not attempt to use the Reflection API to access information that the security rules of the Java programming language make unavailable.

所以一般来说 - 你不应该违反语言定义的安全规则。