Java检测类是否是代理 [英] Java detect if class is a proxy
本文介绍了Java检测类是否是代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以检测某个类是否是代理(动态, cglib 或否则)?
Is it possible to detect if a class is a proxy (dynamic, cglib or otherwise)?
让类A
和B
实现公共接口I
.然后我需要定义一个例程classEquals
签名
Let classes A
and B
implement a common interface I
. Then I need to define a routine classEquals
of signature
public boolean classEquals(Class<? extends I> a, Class<? extends I> b);
使得
仅在a.equals(b)
或Proxy(a).equals(b)
时才评估为 true ,其中Proxy(a)
表示类型为A
的动态代理(动态,cglib或其他).
such that it evaluates to true only if a.equals(b)
or Proxy(a).equals(b)
, where Proxy(a)
denotes a dynamic proxy of type A
(dynamic, cglib or otherwise).
在@Jigar Joshi
的帮助下,到目前为止是这样:
With the assistance of @Jigar Joshi
, this is what it looks like so far:
public boolean classEquals(Class a, Class b) {
if (Proxy.isProxyClass(a)) {
return classEquals(a.getSuperclass(), b);
}
return a.equals(b);
}
问题是它未检测到 CGLIB 代理.
The problem is that it doesn't detect e.g., a CGLIB proxy.