动态 Java 类代理 djcproxy

码农软件 · 软件分类 · 常用工具包 · 2019-08-15 06:13:19

软件介绍

djcproxy 是一个小型的 Java 库,实现动态 Java 类代理。使用它可以在运行时对已存在的对象创建代理对象,用来创建面向方面特性。例如度量某个方法的执行时间,修改方法行为,记录方法执行等等。

完整示例代码:

protected static class A {
    public A() {
    }

    public int method() {
        return 1;
    }
}

private class Interceptor implements MethodInterceptor {

    @Override
    public Object intercept(Object obj, Method method, Object[] args)
            throws Exception {
        if (method.getName().equals("toString")) {
            return "interceptedToString";
        }
        return 0;
    }

}

@Test
public void given_Object_when_CreatingSource_then_GettingInterceptorResult()
        throws Exception {

    A a = new A();
    ProxyFactory<A> factory = new ProxyFactory<>();
    A s = factory.create(a, new Interceptor());
    Assert.assertEquals("interceptedToString", s.toString());
    Assert.assertEquals(0, s.method());
}

本文地址:https://www.codercto.com/soft/d/12389.html

Web Design Index by Content 3 (Web Design Index)

Web Design Index by Content 3 (Web Design Index)

Pepin Press (EDT) / Pepin Press / 2007-11 / USD 29.99

Would you like an overview of the state of the art in web design in a specific field? WEB DESIGN INDEX BY CONTENT provides exactly that: every year, 500 new designs are selected and grouped in more th......一起来看看 《Web Design Index by Content 3 (Web Design Index)》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具