找的好辛苦呀 原文地址:https://dzone.com/articles/spring-annotation-processing-how-it-works If you see an annotation, there must be some code somewhere to process it. One of the things I emphasize when I teach Java classes is the fact that annotations are inert
如果你看到了注解,那么一定有什么代码在什么地方处理了它. Alan Hohn 我教Java课程时强调的一点是注解是惰性的.换句话说,它们只是标记,可能具有某些属性,但没有自己的行为.因此,每当你在一段Java代码上看到一个注解时,就意味着必须有一些其他的Java代码来寻找那个注解并包含真正的智能来做一些有用的东西. 不幸的是,这种推理的问题在于,确切地确定哪一段代码正在处理注解是非常困难的,特别是如果它在库中.处理注解的代码可能会令人困惑,因为它使用反射并且必须以非常抽象的方式编写.所以我认为值
现在市面上很多框架都有使用到注解,比如butterknife库.EventBus库.Retrofit库等等.也是一直好奇他们都是怎么做到的,注解的工作原理是啥.咱们能不能自己去实现一个简单的注解呢. 注解(Annotation)是JDK1.5新增加功能,注解其实就是添加在类.变量.方法.参数等前面的一个修饰符一个标记而已(不要把他想的太复杂).比如下面的代码里面@Override.@IdRes就是注解. @Override public <T extends View> T findViewB
接口:AnnotatedElement * Represents an annotated element of the program currently running in this * VM. This interface allows annotations to be read reflectively. All * annotations returned by methods in this interface are immutable and * serializable.