@interface使用
来源:互联网 发布:淘宝买家手机号提取 编辑:程序博客网 时间:2024/04/28 04:28
1.类级别
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Element {
int id();String type();
}
2.参数字段
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface MyParam {
String paramName();
}
3.class
@Element(id = 1, type = “boy”)
public class Boy {
@MyParam(paramName = "name")private String name;public String getName() { return name;}public void setName(String name) { this.name = name;}
}
4.测试类
public class Test {
public static void main(String[] args) { Element loveElement = Boy.class.getAnnotation(Element.class); System.out.println(loveElement.id()); System.out.println(loveElement.type()); Field[] fields = Boy.class.getDeclaredFields(); for (Field field : fields) { MyParam myParam = field.getAnnotation(MyParam.class); System.out.println(field.getName()); System.out.println(myParam.paramName()); }}
}
1 0
- interface 使用
- @interface使用
- 【interface】C#interface定义及使用浅析
- Interface定义及使用
- C# 接口使用 (interface)
- 使用dnet操作interface
- interface builder 使用 1
- Interface Builder 使用技巧
- GO interface的使用
- 接口 Interface的使用
- 使用@interface 自定义注解
- @interface使用详解
- 浅谈Interface使用01
- javax KeyManager(interface)使用解析
- Purebasic中Interface的使用
- java 接口interface的使用
- Interface Builder 使用教程集锦
- interface 的使用案例1
- LeetCode 138. Copy List with Random Pointer
- centos6u3安装stringi时遇到的问题及解决
- String类的构造
- flume1.6.0的安装
- Eclipse实现安卓客户端的版本更新
- @interface使用
- 【网络优化】超轻量级网络SqueezeNet算法详解
- iOS开发-----响应链
- Unity学习日常问题记录一
- hdu1234开门人和关门人(水题)
- 使用广播 更新Fragment
- JVM调优总结(3):垃圾回收面临的问题
- luac 编译器
- 线性代数导论5——SVD分解