在Java中,如何动态地将任何注释放在指定包内的类声明中?
在Java中,如何在指定包内的类声明上动态添加任何注释?
package-info.java 能做到吗?
如果可以的话怎么写?
In Java, how to dynamically put any annotations on the declaration of classes within the specified package ?
Is the package-info.java able to do it ?
How to write it if can ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除非使用动态字节码生成器,例如 Javassist 。
Unless dynamical byte code generator such as Javassist is used.
我假设您要求的是自动以某种方式注释给定包中的所有类。
那是不可能的。
您绝对可以通过字节码操作来完成此操作(无论是作为构建过程的一部分,还是在类加载期间),但这需要大量工作,并且可能不是您想要的路径。
您可能需要重新考虑您的方法。
您尝试使用的注释是什么?为什么需要所有类都具有该注释?
I assume what you are asking for is some to automatically have all classes within a given package be annotated in some way.
That is not possible.
You could definitely do it with byte-code manipulation (either as part of the build process, or during class-loading), but that's a lot of work, and probably isn't the path you want to head down.
You probably need to rethink your approach here.
What is the annotation that you're trying to use, and why do you need all classes to have that annotation?