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

查看:352
本文介绍了在运行时添加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是我的核心数据类型和接口,这样,商业方法是DB /数据层)商业方法也取决于externalLibrary。就我而言,商业方法是从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天全站免登陆