Java检测类是否是代理 [英] Java detect if class is a proxy

查看:1392
本文介绍了Java检测类是否是代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以检测某个类是否是代理(动态 cglib 否则)?

Is it possible to detect if a class is a proxy (dynamic, cglib or otherwise)?

让类AB实现公共接口I.然后我需要定义一个例程classEquals签名

Let classes Aand 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.

推荐答案

查看全文

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