我必须在标准输出上打印注释写在 Java类上.我怎么能这样做? 例如. /** * Comment to write * @version 1.1 */public class WriteMyComment { //something...} 我宁愿使用注释来做你需要做的事情.我不确定是否
例如.
/**
* Comment to write
* @version 1.1
*/
public class WriteMyComment {
//something...
}
我宁愿使用注释来做你需要做的事情.我不确定是否可以在运行时访问源注释.
MyAnnotation.java
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface MyAnnotation {
String value();
}
Test.java
@MyAnnotation("Some notes here")
public class Test {
public static void main(String[] args) {
System.out.println(Test.class.getAnnotation(MyAnnotation.class).value());
}
}
