码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2015-05-18 22:49:39      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:

 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 }

 

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

标签:

原文地址:http://www.cnblogs.com/kanchihong/p/4513195.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!