动态 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://codercto.com/soft/d/12389.html

The Smashing Book

The Smashing Book

Jacob Gube、Dmitry Fadeev、Chris Spooner、Darius A Monsef IV、Alessandro Cattaneo、Steven Snell、David Leggett、Andrew Maier、Kayla Knight、Yves Peters、René Schmidt、Smashing Magazine editorial team、Vitaly Friedman、Sven Lennartz / 2009 / $ 29.90 / € 23.90

The Smashing Book is a printed book about best practices in modern Web design. The book shares technical tips and best practices on coding, usability and optimization and explores how to create succes......一起来看看 《The Smashing Book》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

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

在线图片转Base64编码工具

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

UNIX 时间戳转换