注释 SOURCE 保留政策

Annotation SOURCE Retention Policy(注释 SOURCE 保留政策)
本文介绍了注释 SOURCE 保留政策的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

来自 Java 文档:

From the Java doc:

类:注释将由编译器记录在类文件中,但不需要在运行时由 VM 保留.

CLASS: Annotations are to be recorded in the class file by the compiler but need not be retained by the VM at run time.

运行时间:注释将由编译器记录在类文件中,并在运行时由 VM 保留,因此可以反射性地读取它们.

RUNTIME: Annotations are to be recorded in the class file by the compiler and retained by the VM at run time, so they may be read reflectively.

来源:注释将被编译器丢弃.

SOURCE: Annotations are to be discarded by the compiler.

我了解 RUNTIME(为了使用带反射的注解)和 CLASS(对于编译器)的用法,但我不明白什么时候可以使用

I understand the usages of RUNTIME (in order to use annotation with reflection) and CLASS (for the compiler) but I don't understand when it can be usefull to use

@Retention(RetentionPolicy.SOURCE)

@Retention(RetentionPolicy.SOURCE)

你能解释一下吗?

推荐答案

像@SuppressWarnings、@Override 这样的东西是编译器使用的注解——在运行时不需要.对于那些 RetentionPolicy.SOURCE 是有意义的.注释也可用于生成代码(查看 Spring ROO)——在运行时也不需要此类注释.

Things like @SuppressWarnings, @Override are annotations used by the compiler - not needed at runtime. For those RetentionPolicy.SOURCE would make sense. Also annotations can be used to generate code (look at Spring ROO) - such annotation are also not required at run time.

这篇关于注释 SOURCE 保留政策的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)