Java注解什么时候执行? [英] When are Java annotations executed?

查看:78
本文介绍了Java注解什么时候执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想写一些可以在运行时、调用服务方法之前或之后立即执行的注释.

I am just looking to write some annotation which can execute at runtime, before or immediately after a service method is invoked.

我不知道它们是在运行时执行还是在编译时执行.

I don't know if they are executed at runtime or compile time.

推荐答案

注解不执行;它们是由各种工具读取的笔记或标记.有些是由你的编译器读取的,比如 @Override;其他人嵌入在类文件中,并在运行时由 Hibernate 等工具读取.但他们自己什么都不做.

Annotations don't execute; they're notes or markers that are read by various tools. Some are read by your compiler, like @Override; others are embedded in the class files and read by tools like Hibernate at runtime. But they don't do anything themselves.

您可能会想到断言 代替,可用于验证前置和后置条件.

You might be thinking of assertions instead, which can be used to validate pre and post conditions.

这篇关于Java注解什么时候执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆