8000 Merge pull request #95 from billwang22/master · coderli7/toBeTopJavaer@bdca72a · GitHub
[go: up one dir, main page]

Skip to content

Commit bdca72a

Browse files
authored
Merge pull request hollischuang#95 from billwang22/master
Update annotion-and-reflect.md
2 parents 43ab298 + f1a3b21 commit bdca72a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

docs/basics/java-basic/annotion-and-reflect.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public class MyTest {
7272
Class clazz = obj.getClass();
7373
Field[] declareFields = clazz.getDeclaredFields();
7474
for (Field field:declareFields) {
75-
//检查该类是否使用了某个注解
76< 7617 /code>-
if(clazz.isAnnotationPresent(MyAnno.class)){
75+
//检查该字段是否使用了某个注解
76+
if(field.isAnnotationPresent(MyAnno.class)){
7777
MyAnno anno = field.getAnnotation(MyAnno.class);
7878
if(anno!=null){
7979
String fieldName = field.getName();
@@ -110,4 +110,4 @@ Person(stra=有注解, strb=无注解, strc=无注解)
110110
111111
当开发者使用了Annotation 修饰了类、方法、Field 等成员之后,这些 Annotation 不会自己生效,必须由开发者提供相应的代码来提取并处理 Annotation 信息。这些处理提取和处理 Annotation 的代码统称为 APT(Annotation Processing Tool)。
112112
113-
注解的提取需要借助于 Java 的反射技术,反射比较慢,所以注解使用时也需要谨慎计较时间成本。
113+
注解的提取需要借助于 Java 的反射技术,反射比较慢,所以注解使用时也需要谨慎计较时间成本。

0 commit comments

Comments
 (0)
0