How do annotations like @Override work internally in Java?

前端 未结 6 859
粉色の甜心
粉色の甜心 2020-12-02 03:56

Can anybody explain to me how annotations work internally in java?

I know how we can create custom annotations by using java.lang.annotation library in java. But I s

6条回答
  •  独厮守ぢ
    2020-12-02 04:36

    Basically, annotations are just markers which are read by the compiler or the application. Depending on their retention policy they are available at compile time only or are readable at runtime using reflection.

    Many frameworks use runtime retention, i.e. they reflectively check whether some annotations are present on a class, method, field etc. and do something if the annotation is present (or not). Additionally, members of annotations can be used to pass further information.

提交回复
热议问题