安卓中級教程(7):annotation中的 public @interface的用法

 1 package com.example.ele_me.util;
 2 
 3 import java.lang.annotation.Retention;
 4 import java.lang.annotation.Target;
 5 import java.lang.annotation.ElementType;  
 6 import java.lang.annotation.RetentionPolicy;  
 7 
 8 /** 
 9  * Use this annotation to mark the fields of your Activity as being injectable. 
10  * <p> 
11  * See the {@link Injector} class for more details of how this operates. 
12  */  
13 @Target({ ElementType.FIELD })  
14 @Retention(RetentionPolicy.RUNTIME)  
15 public @interface InjectView {  
16     /** 
17      * 這個java檔最精彩的地方是@interface,一般我們皆看到public Class去定義類型,而在injectview.java這裡卻使用了這樣public @interface的方法。
18      */  
19     public int value();  
20 //所有對象都會被寫進value這個函數之中。
21 }  java.lang.annotation.Retention;

value()所得到的對象內容,會同時被寫進@Target和@Retention之中,當你打開這兩個變數時,你會發現它所包含的東西是如此豐富:

 

1 public enum RetentionPolicy { 
2 SOURCE, 
3 CLASS, 
4 RUNTIME 
5 }

 

1 public enum ElementType { 
2 TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, 
3 LOCAL_VARIABLE, ANNOTATION_TYPE,PACKAGE 
4 }

 

转载于:https://www.cnblogs.com/kanchihong/p/4513195.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值