Java注释何时执行? [英] When are Java annotations executed?

查看:119
本文介绍了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天全站免登陆