Ste*_*eve 5 java reflection annotations
我有一个Class<? extends Annotation>
并且尝试过调用newInstance()
但是Java因为我无法实例化接口的明显原因而对我大吼大叫.但我知道像EasyMock这样的框架完全能够实例化接口.Annotation
从我的身上得到一个完全愚蠢的实例需要Class
什么?
感谢Affe指出了正确的方向 - 我会评论他的答案,但后来我无法格式化解决方案:
Annotation annotation = (Annotation) Proxy.newProxyInstance( clazz.getClassLoader(), new Class[] { Annotation.class }, new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) { return clazz; // only getClass() or annotationType() should be called. } });奇迹般有效.
归档时间: |
|
查看次数: |
6670 次 |
最近记录: |