JAVA之注解(代码)
来源:互联网 发布:营销型企业网站源码 编辑:程序博客网 时间:2024/06/08 16:36
package cn.com.annotation;
/**
* 自定义的一个注解
*/
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
String hello() default "哈哈哈";
String hi();
/**
* 自定义的一个注解
*/
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
String hello() default "哈哈哈";
String hi();
}
package cn.com.annotation;
/**
* 使用注解
*/
@MyAnnotation(hi = "嗨")
public class MyTest {
@MyAnnotation(hi = "haha")
@Deprecated
public void output() {
System.out.println("打印");
}
}
package cn.com.annotation;
/**
* 通过反射测试注解
*/
import java.lang.reflect.Method;
public class MyReflection {
public static void main(String[] args) throws Exception {
MyTest test = new MyTest();
Class<MyTest> classType = MyTest.class;
Method method = classType.getMethod("output", new Class[]{});
if(method.isAnnotationPresent(MyAnnotation.class)) {
method.invoke(test, new Object[]{});
MyAnnotation my = method.getAnnotation(MyAnnotation.class);
String hi = my.hi();
String hello = my.hello();
System.out.println(hi + ", " + hello);
}
}
}
- JAVA之注解(代码)
- java之注解(代码2)
- java之注解(一)
- Java之注解(Annotation)
- spring AOP 之 注解 配置实现(附 Java 代码实例)
- spring AOP 之 注解 配置实现(附 Java 代码实例)
- java之注解 自定义注解
- Java注解之常用注解
- java注解之初识注解
- Java进阶之Annotation(注解)——自定义注解
- java annotation (注解)之我见(一)
- java注解(2)之应用实例
- [Java开发之路](15)注解
- Java进阶之Annotation(注解)
- java之注解
- java之注解
- Java高新技术之注解
- Java之注解篇
- 国家集训队论文分类
- android中如何实现连续点击返回键退出整个应用 android两次返回退出应用
- 杂锦
- 原样输出最长回文子串
- Linux菜鸟学习笔记(一)--Linux系统结构
- JAVA之注解(代码)
- Git学习笔记05--git stash
- bwareaopen
- poj 2253
- HOW-TO: Compile Mplayer.dll
- JBoss下载and安装
- C++之插入排序
- Import原理,避免误区
- linux c/c++ 编程之-----gdb 使用