java - java中的符号表和反射

标签 java spring reflection

看来java的反射需要将符号表编译到class文件中。但出于性能考虑,在运行时我们通常将其删除。 (我不懂java,用c++,我们真的把它移到了生产主管中)。

我的问题是,如果我删除符号表,这是否意味着某些库(例如 spring)将无法正常运行?

ps:

来自 Berthold Daum 的 Professional Eclipse 3 for Java™Developers

Classfiles and JDK Compliance On the Compliance & Classfiles page you can specify which symbolic information, such as variable names and line numbers, is to be included in the generated classfiles. This information is required for debugging, and therefore you may want to leave the proposed settings unchanged. However, for a welltested program it may make sense to remove this information from the classfiles; generated files are much smaller without the symbol tables.

最佳答案

一般来说,很难知道反射代码可能使用什么、不使用什么。像 Spring 这样的框架可能会使用运行时可用的调试信息。

以Spring的@PreAuthorize和相关注解为例。在 documentation ,我们看到以下内容:

You can access any of the method arguments by name as expression variables, provided your code has debug information compiled in.

因此,您在编译后删除调试信息所采取的任何步骤都必须经过彻底测试,或者必须知道您的代码不包含上述模式。

但请注意,标准 Java 反射库不提供此反射。有关如何在 Java 中完成此操作的更多信息,请参阅 this answer .

关于java - java中的符号表和反射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22774112/

相关文章:

java - Tomcat 中的 JNDI 配置

java - java中的支付网关集成

java - Spring依赖@PostConstruct

spring - Hadoop JobRunner不启 Action 业

C# 动态表单(反射)-链接控件

.net - 为什么查找类型的初始值设定项会抛出 NullReferenceException?

java - 向java代码添加延迟

java - Oracle 驱动程序可能不在使用任务 "gradle jar"的类路径中

spring - Spring事务中发生死锁时调度程序停止

java - 对要打印的对象属性的自省(introspection)