java注解demo
来源:互联网 发布:巴西农业部数据 mapa 编辑:程序博客网 时间:2024/06/05 04:30
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface MyAnnotationClass {
public String msg();
}
package org.annation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface MyAnnotationMethod {
public String common();
}
package org.annation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface MyAnnotationField {
boolean request();
}
package org.annation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class MyAnnotationTest {
public static void main(String[] args) {
MyAnnotationDemo demo = new MyAnnotationDemo();
MyAnnotationClass annotationClass = demo.getClass().getAnnotation(
MyAnnotationClass.class);
System.out.println(annotationClass.msg());
Method method = null;
try {
method = demo.getClass().getMethod("method", new Class[0]);
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
MyAnnotationMethod annotationMethod = method
.getAnnotation(MyAnnotationMethod.class);
System.out.println(annotationMethod.common());
Field field = null;
try {
field = demo.getClass().getDeclaredField("hello");
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
MyAnnotationField annotationField = field
.getAnnotation(MyAnnotationField.class);
System.out.println(annotationField.request());
}
}
- [java]自定义注解demo
- java注解demo
- java 注解demo
- java注解____注解的入门demo
- 注解demo
- java springMVC demo 事例 注解模式 例子 完整事例
- JAVA自定义注解实现SQL语句自动生成DEMO
- Form Demo 注解(ST1)
- spring aop注解Demo
- hibernate注解demo
- 自定义注解Demo
- Spring 注解 Demo
- 自定义注解Demo
- Spring注解Demo
- [ java]注解的使用2————Type 获取包下面有@Controller的注解 demo
- 多线程学习Demo注解(1)
- spring mvc 基于注解demo
- 反射+泛型+注解(demo)
- POJ - 1258 Agri-Net (裸Kruskal)
- VMWare安装redhat9后上网的的问题
- statusbar—上通知条
- 解决使用AJAX传中文参数乱码问题
- a:link,a:visited,a:hover,a:active
- java注解demo
- Unity 3D 开发技巧分享&工具推荐
- Java Web 监听器 (计算在线人数)
- 使用Qt实现MDI风格的主窗体
- 内核中与驱动相关的内存操作之十六(异步I/O)
- MySQL常用到的一些phpmyadmin配置总结
- 指针常量和常量指针
- 点到线段的垂直距离
- webview出错