Skip to content

Commit 080aae2

Browse files
committed
add file
1 parent d93fb5c commit 080aae2

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

Android加强/注解使用.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
RxJava详解
2+
===
3+
4+
###简介
5+
6+
> Annotations, a form of metadata, provide data about a program that is not part of the program itself. Annotations have no direct effect on the operation of the code they annotate.
7+
8+
更通俗的意思是为程序的元素(类、方法、成员变量)加上更直观更明了的说明,这些说明信息是与程序的业务逻辑无关,并且是供指定的工具或框架使用的。
9+
`Annontation`像一种修饰符一样,应用于包、类型、构造方法、方法、成员变量、参数及本地变量的声明语句中。
10+
11+
`Annotation`其实是一种接口。通过反射来访问`annotation`信息。相关类(框架或工具中的类)根据这些信息来决定如何使用该程序元素或改变它们的行为。
12+
`Annotation`是不会影响程序代码的执行,无论`annotation`怎么变化,代码都始终如一地执行。
13+
`Java`语言解释器在工作时会忽略这些`annotation`,因此在`JVM`中这些`annotation`是“不起作用”的,只能通过配套的工具才能对这些`annontaion`类型的信息进行访问和处理。
14+
15+
###说明
16+
- `Annotation`的声明是通过关键字`@interface`。这个关键字会去继承`Annotation`接口。
17+
- `Annotation`的方法定义是独特的、受限制的。
18+
`Annotation`类型的方法必须声明为无参数、无异常的。这些方法定义了`Annotation`的成员: 方法名代表成员变量名,而方法返回值代表了成员变量的类型。而且方法的返回值类型必须是基本数据类型、`Class`类型、枚举类型、`Annotation`类型或者由前面类型之一作为元素的一维数组。方法的后面可以使用`default`和一个默认的数值来声明成员变量的默认值,`null`不能作为成员变量的默认值,这与我们平时的使用有很大的区别。
19+
20+
例如:
21+
```java
22+
@Target(ElementType.METHOD)
23+
@Retention(RetentionPolicy.RUNTIME)
24+
public @interface UseCase {
25+
public int id();
26+
public String description() default "no description";
27+
}
28+
```
29+
30+
###作用
31+
32+
`Annotation`一般作为一种辅助途径,应用在软件框架或者工具中。让这些工具类可以根据不同的`Annotation`注解信息来采取不同的处理过程或者改变相应程的行为。
33+
34+
35+
###Annotation分类
36+
37+
38+
#####标准的`Annotaion`
39+
40+
`jdk 1.5`开始,自带了三种标准的`annotation`类型:
41+
42+
- `Override`
43+
它是一种`marker`类型的`Annotation`,用来标注方法,说明被它标注的方法是重载了父类中的方法。如果我们使用了该注解到一个没有覆盖父类方法的方法时,编译器就会提示一个编译错误的警告。
44+
45+
- `Deprecated`
46+
它也是一种`marker`类型的`Annotation`。当方法或者变量使用该注解时,编译器就会提示该方法已经废弃。
47+
48+
- `SuppressWarnings`
49+
它不是`marker`类型的`Annotation`。用户告诉编译器不要再对该类、方法或者成员变量进行警告提示。
50+
51+
52+
#####元`Annotation`
53+
54+
`Annotation`是指用来定义`Annotation``Annotation`
55+
56+
- `@Retention
57+
58+
- `@Target`
59+
60+
- `@Inherited`
61+
62+
- `@Documented`
63+
64+
#####自定义`Annotation`
65+
66+
67+
68+
69+
---
70+
71+
- 邮箱 :charon.chui@gmail.com
72+
- Good Luck!

0 commit comments

Comments
 (0)