不会啊,没有问题的,我在下面又测试了一下主方法上是否有注解,你看一下- public class AnnotationTest1{
- private static ItheimaAnnotation annotation;
- @ItheimaAnnotation
- public static void main(String[] args) throws NoSuchMethodException, SecurityException {
- if(AnnotationTest1.class.isAnnotationPresent(ItheimaAnnotation.class)){
- annotation = AnnotationTest1.class.getAnnotation(ItheimaAnnotation.class);
- System.out.println(annotation);
- }
- else
- System.out.println("类上没有注解");
- //测试方法上是否有注解,有则打印,否则退出
- Method methodMain = AnnotationTest1.class.getMethod("main", String[].class);
- if(methodMain.isAnnotationPresent(ItheimaAnnotation.class)){
- annotation = methodMain.getAnnotation(ItheimaAnnotation.class);
- System.out.println(annotation);
- }
- else
- return;
- }
- }
复制代码 |