标签:intellij beans rda ref deploy nashorn yaml VID exception
https://www.newsmth.net/nForum/#!article/WorkLife/2325222
package com.example.annotationdemo.retention;
/**
* 源码有
*/
@SourceAnnotation
public class A1 {
}
package com.example.annotationdemo.retention;
public class A2 {
}
package com.example.annotationdemo.retention;
/**
* class有
* JVM忽略
*/
@ClassAnnotation
public class B1 {
}
package com.example.annotationdemo.retention;
public class B2 {
}
package com.example.annotationdemo.retention;
@RuntimeAnnotation
public class C1 {
}
package com.example.annotationdemo.retention;
public class C2 {
}
package com.example.annotationdemo.retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* class文件会包括这个注解
* JVM运行的时候会忽略掉部分注解
*/
@Retention(RetentionPolicy.CLASS)
public @interface ClassAnnotation {
}
package com.example.annotationdemo.retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* class包括这个注解
* 并且JVM加载时也会把这部分注解加载进来
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface RuntimeAnnotation {
}
package com.example.annotationdemo.retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* 只保留在源码级别上的注解
*/
@Retention(RetentionPolicy.SOURCE)
public @interface SourceAnnotation {
}
package com.example.annotationdemo.retention;
public class RetentionTestMain {
public static void main(String[] args) throws Exception{
//RetentionPolicy.SOURCE
//注解不会保存到class文件
//这种注解一般是提供给IDE环境做源码的质量分析和监控的
Class a1 = Class.forName("com.example.annotationdemo.retention.A1");
Class a2 = Class.forName("com.example.annotationdemo.retention.A2");
System.out.println(a1.getAnnotations().length);
System.out.println(a2.getAnnotations().length);
System.out.println("==========================");
//RetentionPolicy.CLASS
//注解会保存到class文件中,但是不会被JVM加载
Class b1 = Class.forName("com.example.annotationdemo.retention.B1");
Class b2 = Class.forName("com.example.annotationdemo.retention.B2");
System.out.println(b1.getAnnotations().length);
System.out.println(b2.getAnnotations().length);
System.out.println("==========================");
//RetentionPolicy.RUNTIME
//注解会保存在class文件中,且会被JVM加载,反射识别
Class c1 = Class.forName("com.example.annotationdemo.retention.C1");
Class c2 = Class.forName("com.example.annotationdemo.retention.C2");
System.out.println(c1.getAnnotations().length);
System.out.println(c2.getAnnotations().length);
System.out.println("==========================");
}
}
F:\jdk1.8.0_201\bin\java.exe "-javaagent:F:\IntelliJ IDEA 2020\lib\idea_rt.jar=63781:F:\IntelliJ IDEA 2020\bin" -Dfile.encoding=UTF-8 -classpath F:\jdk1.8.0_201\jre\lib\charsets.jar;F:\jdk1.8.0_201\jre\lib\deploy.jar;F:\jdk1.8.0_201\jre\lib\ext\access-bridge-64.jar;F:\jdk1.8.0_201\jre\lib\ext\cldrdata.jar;F:\jdk1.8.0_201\jre\lib\ext\dnsns.jar;F:\jdk1.8.0_201\jre\lib\ext\jaccess.jar;F:\jdk1.8.0_201\jre\lib\ext\jfxrt.jar;F:\jdk1.8.0_201\jre\lib\ext\localedata.jar;F:\jdk1.8.0_201\jre\lib\ext\nashorn.jar;F:\jdk1.8.0_201\jre\lib\ext\sunec.jar;F:\jdk1.8.0_201\jre\lib\ext\sunjce_provider.jar;F:\jdk1.8.0_201\jre\lib\ext\sunmscapi.jar;F:\jdk1.8.0_201\jre\lib\ext\sunpkcs11.jar;F:\jdk1.8.0_201\jre\lib\ext\zipfs.jar;F:\jdk1.8.0_201\jre\lib\javaws.jar;F:\jdk1.8.0_201\jre\lib\jce.jar;F:\jdk1.8.0_201\jre\lib\jfr.jar;F:\jdk1.8.0_201\jre\lib\jfxswt.jar;F:\jdk1.8.0_201\jre\lib\jsse.jar;F:\jdk1.8.0_201\jre\lib\management-agent.jar;F:\jdk1.8.0_201\jre\lib\plugin.jar;F:\jdk1.8.0_201\jre\lib\resources.jar;F:\jdk1.8.0_201\jre\lib\rt.jar;C:\Users\Administrator\IdeaProjects\geektime-spring-family-learning\annotation-demo\target\classes;C:\Users\Administrator\.m2\repository\org\springframework\boot\spring-boot-starter\2.2.6.RELEASE\spring-boot-starter-2.2.6.RELEASE.jar;C:\Users\Administrator\.m2\repository\org\springframework\boot\spring-boot\2.2.6.RELEASE\spring-boot-2.2.6.RELEASE.jar;C:\Users\Administrator\.m2\repository\org\springframework\spring-context\5.2.5.RELEASE\spring-context-5.2.5.RELEASE.jar;C:\Users\Administrator\.m2\repository\org\springframework\spring-aop\5.2.5.RELEASE\spring-aop-5.2.5.RELEASE.jar;C:\Users\Administrator\.m2\repository\org\springframework\spring-beans\5.2.5.RELEASE\spring-beans-5.2.5.RELEASE.jar;C:\Users\Administrator\.m2\repository\org\springframework\spring-expression\5.2.5.RELEASE\spring-expression-5.2.5.RELEASE.jar;C:\Users\Administrator\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.2.6.RELEASE\spring-boot-autoconfigure-2.2.6.RELEASE.jar;C:\Users\Administrator\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.2.6.RELEASE\spring-boot-starter-logging-2.2.6.RELEASE.jar;C:\Users\Administrator\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\Administrator\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\Administrator\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.12.1\log4j-to-slf4j-2.12.1.jar;C:\Users\Administrator\.m2\repository\org\apache\logging\log4j\log4j-api\2.12.1\log4j-api-2.12.1.jar;C:\Users\Administrator\.m2\repository\org\slf4j\jul-to-slf4j\1.7.30\jul-to-slf4j-1.7.30.jar;C:\Users\Administrator\.m2\repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;C:\Users\Administrator\.m2\repository\org\springframework\spring-core\5.2.5.RELEASE\spring-core-5.2.5.RELEASE.jar;C:\Users\Administrator\.m2\repository\org\springframework\spring-jcl\5.2.5.RELEASE\spring-jcl-5.2.5.RELEASE.jar;C:\Users\Administrator\.m2\repository\org\yaml\snakeyaml\1.25\snakeyaml-1.25.jar;C:\Users\Administrator\.m2\repository\org\slf4j\slf4j-api\1.7.30\slf4j-api-1.7.30.jar com.example.annotationdemo.retention.RetentionTestMain
0
0
==========================
0
0
==========================
1
0
==========================
Process finished with exit code 0
标签:intellij beans rda ref deploy nashorn yaml VID exception
原文地址:https://www.cnblogs.com/ukzq/p/13284144.html