动态 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

Distributed Algorithms

Distributed Algorithms

Wan Fokkink / The MIT Press / 2013-12-6 / USD 40.00

This book offers students and researchers a guide to distributed algorithms that emphasizes examples and exercises rather than the intricacies of mathematical models. It avoids mathematical argumentat......一起来看看 《Distributed Algorithms》 这本书的介绍吧!

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

在线图片转Base64编码工具

URL 编码/解码
URL 编码/解码

URL 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器