是否可以在给定 Class<的情况下实例化 Java Annotation?扩展注解>? [英] Is it possible to instantiate a Java Annotation given a Class&lt;? extends Annotation&gt;?

查看:36
本文介绍了是否可以在给定 Class<的情况下实例化 Java Annotation?扩展注解>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Class 并尝试调用 newInstance() 但 Java 对我大喊大叫,原因很明显,我无法实例化接口.但我知道像 EasyMock 这样的框架完全能够实例化接口.从我的 Class 中获取一个完全愚蠢的 Annotation 实例需要什么?

I have a Class<? extends Annotation> and tried calling newInstance() but Java yelled at me for the obvious reason that I can't instantiate an interface. But I know frameworks like EasyMock are perfectly capable of instantiating interfaces. What would it take to get a completely dumb Annotation instance out of my Class?

推荐答案

Mock 框架不实例化接口,它们构建的类在运行时即时实现它们.您可能会发现此 javadoc 启发你想做什么!

Mock frameworks do not instantiate interfaces, they build classes that implement them on the fly at runtime. You may find this javadoc enlightening for what you want to do!

这篇关于是否可以在给定 Class<的情况下实例化 Java Annotation?扩展注解>?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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