- package JDK1_5;
- import java.lang.annotation.Annotation;
- @ItcastAnnotation(value = "cc", color="red")
- public class AnnotationTest {
- // @ItcastAnnotation(value="cc",color="red")
- public static void main(String[] args) {
- if (AnnotationTest.class.isAnnotationPresent(ItcastAnnotation.class)) {
- ItcastAnnotation annotation = (ItcastAnnotation) Annotation.class.getAnnotation(ItcastAnnotation.class);
- System.out.println(annotation.color());
- }
- }
- }
- package JDK1_5;
- import java.lang.annotation.Retention;
- import java.lang.annotation.*;
- @Retention(RetentionPolicy.RUNTIME)
- @Target({ ElementType.METHOD, ElementType.TYPE })
- public @interface ItcastAnnotation {
- String color() default "blue";
- String value();
- }
复制代码 实在找不到哪里错了。。跟张老师的一模一样,JDK我的是1.7的。 为什么报错:java.lang.NullPointerException
|