在运行时添加 Java 注释 [英] Adding Java Annotations at Runtime

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

问题描述

是否可以在运行时向对象(特别是在我的情况下,方法)添加注释?

Is it possible to add an annotation to an object (in my case in particular, a Method) at runtime?

更多解释:我有两个模块,moduleA 和 moduleB.moduleB 依赖于 moduleA,它不依赖于任何东西.(modA 是我的核心数据类型和接口等,modB 是数据库/数据层) modB 也依赖于 externalLibrary.就我而言,modB 正在将一个类从 modA 移交给 externalLibrary,这需要对某些方法进行注释.具体的注释都是 externalLib 的一部分,正如我所说,modA 不依赖于 externalLib,我想保持这种方式.

For a bit more explanation: I have two modules, moduleA and moduleB. moduleB depends upon moduleA, which doesn't depend upon anything. (modA is my core datatypes and interfaces and such, modB is db/data layer) modB also depends on externalLibrary. In my case, modB is handing off a class from modA to externalLibrary, which needs certain methods to be annotated. The specific annotations are all part of externalLib and, as I said, modA doesn't depend on externalLib and I'd like to keep it that way.

那么,这可能吗,或者您对解决此问题的其他方法有什么建议吗?

So, is this possible, or do you have suggestions for other ways of looking at this problem?

推荐答案

在运行时添加注解是不可能的,听起来你需要引入一个适配器,模块 B 用来包装来自模块 A 的对象,以暴露所需的带注释的方法.

It's not possible to add an annotation at runtime, it sounds like you need to introduce an adapter that module B uses to wrap the object from module A exposing the required annotated methods.

这篇关于在运行时添加 Java 注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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