import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import cn.itcast.day1.EnumTest;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD,ElementType.TYPE})
public @interface ItcastAnnotation {
String color() default "blue";
String value();
int[] arrayAttr() default {3,4,4};
EnumTest.TrafficLamp lamp() default EnumTest.TrafficLamp.RED;
MetaAnnotation annotationAttr() default @MetaAnnotation("lhm");
Class classAttr() default String.class;
}
----------------------------------------------
import java.lang.reflect.Method;
//import javax.jws.soap.InitParam;
@ItcastAnnotation(classAttr=Integer.class,annotationAttr=@MetaAnnotation("flx"),color="red",value="abc",arrayAttr=1)
public class AnnotationTest {
/**
* @param args
*/
@SuppressWarnings("deprecation")
@ItcastAnnotation("xyz")
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
System.runFinalizersOnExit(true);
if(AnnotationTest.class.isAnnotationPresent(ItcastAnnotation.class)){
ItcastAnnotation annotation = (ItcastAnnotation)AnnotationTest.class.getAnnotation(ItcastAnnotation.class);
System.out.println(annotation.color());
System.out.println(annotation.value());
System.out.println(annotation.arrayAttr()/*.length*/);
System.out.println(annotation.lamp().nextLamp().name());
System.out.println(annotation.annotationAttr().value());
System.out.println(annotation.classAttr());
}
Method mainMethod = AnnotationTest.class.getMethod("main", String[].class);
ItcastAnnotation annotation2 = (ItcastAnnotation)mainMethod.getAnnotation(ItcastAnnotation.class);
System.out.println(annotation2.value());
}
@Deprecated
public static void sayHello(){
System.out.println("hi,���Dz���");
}
}
-------------------------------------
public @interface MetaAnnotation {
String value();
}
分享到:
相关推荐
java注解代码java注解代码java注解代码java注解代码java注解代码java注解代码java注解代码java注解代码java注解代码java注解代码java注解代码java注解代码java注解代码java注解代码java注解代码java注解代码java注解...
java 自定义注解验证 可自己添加所需要的注解,本案例中只写了三个自定义注解类 本案例只花了半天时间,如有不好之处请多提提意见。谢谢!
包括Java自定义注解以及包括自定义注解的应用实例。以及注解相关知识的注解
本文档简述了有关javabean中id的注解解释,注解本来就很繁琐,但是学好的话用起来还是比较方便的
使用Java自定义注解来拼接SQL查询语句,方便使用。
Java Annotation注解技术
Java注解实现
java 元注解+拦截器实现自定义注解 @CmwAutoWired:自定义依赖注入 注意:注入的接口和实现类需要在同一包名下,注解的是类则无限制 @FieldAnnotation:自定义属性注解 @MethodAnnotation:自定义方法注解 @...
NULL 博文链接:https://forestqqqq.iteye.com/blog/2235230
注解目前非常的流行,很多主流框架都支持注解,而且自己编写代码的时候也会尽量的去用注解,一时方便,而是代码更加简洁。 注解的语法比较简单,除了@符号的使用之外,它基本...Java还提供了4中注解,专门负责新注
java中(注解符)处理Clob(blob)类型
java动态代理对象实现日志输出,另外再配上annotation实现注解输出。
主要介绍了java中注解机制及其原理的详解的相关资料,希望通过本文能帮助到大家,让大家理解掌握这部分内容,需要的朋友可以参考下
java注解和反射的个人学习笔记
里边主要是 junit-4.12.jar hamcrest-core-1.3.jar l两个jar包,是使用junit4,单元测试需要导入的包
Spring java注解,元注解和自定义注解 Spring java注解,元注解和自定义注解 Spring java注解,元注解和自定义注解 Spring java注解,元注解和自定义注解 Spring java注解,元注解和自定义注解
本注解,通过代码对java,struts,spring,hibernate内的各种情况进行解释,是不可多得的资料
java_注解作用java_注解作用
Java元注解是Java注解的重要特性,下面我就来详解常见的4大Java元注解
自定义注解和通过反射获取注解