Java中的注解处理是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2146104/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 04:06:29  来源:igfitidea点击:

What is annotation processing in Java?

javaannotationsjavac

提问by Xolve

Quoting, Sun's Official Java Tutorial

引用,Sun 的官方 Java 教程

Class names, 'HelloWorldApp', are only accepted if annotation processing is explicitly requested

类名称“HelloWorldApp”仅在明确请求注释处理时才被接受

What does it mean? And how to apply it?

这是什么意思?以及如何应用它?

采纳答案by Arne Deutsch

"Annotation Processing" is a hook into the compile process of the java compiler, to analyse the source code for user defined annotations and handle then (by producing compiler errors, compiler warning, emitting source code, byte code ...).

“注解处理”是java编译器编译过程的一个钩子,分析用户定义注解的源代码并处理(通过产生编译器错误,编译器警告,发出源代码,字节码......)。

API reference: http://java.sun.com/javase/6/docs/api/javax/annotation/processing/package-summary.html

API参考:http: //java.sun.com/javase/6/docs/api/javax/annotation/processing/package-summary.html

回答by Paul Wagland

From the very next line of the pagethat you refer to:

从您引用的页面的下一行开始:

Class names, 'HelloWorldApp', are only accepted if annotation processing is explicitly requested

If you receive this error, you forgot to include the .java suffix when compiling the program. Remember, the command is javac HelloWorldApp.java not javac HelloWorldApp.

类名称“HelloWorldApp”仅在明确请求注释处理时才被接受

如果您收到此错误,则您在编译程序时忘记包含 .java 后缀。请记住,命令是 javac HelloWorldApp.java 而不是 javac HelloWorldApp。

That is, the string that you are referring to is a possible error that you might get when trying to compile the examples. The very nextline in the document, tells you how to resolve the issue.

也就是说,您所指的字符串可能是您在尝试编译示例时可能遇到的错误。在第二天的文件中线上,告诉你如何解决这个问题。

If you want to know more about annotations, what they are, and how to use them, then I would suggest to go through the Annotations tutorial.

如果您想了解更多关于注解、它们是什么以及如何使用它们,那么我建议您阅读注解教程

回答by jaibardhan

This error is due to incorrect use of java compilation command i.e javac with file name w/o java extension (.java)

这个错误是由于错误地使用了 java 编译命令,即文件名没有 java 扩展名 (.java) 的 javac

Use proper compilation command

使用正确的编译命令

javac HelloWorldApp.java

javac HelloWorldApp.java

Command used foe execution

命令使用敌人执行

java HelloWorldApp

java HelloWorldApp