生成两个对象,代理过去就好,参考如下代码:
package com.bixuebihui;
import org.junit.Test;
public class ProxyTest {
interface IA{
void methodA();
}
public static class A implements IA{
@Override
public void methodA() {
System.out.println("A");
}
}
interface IB{
void methodB();
}
public static class B implements IB{
@Override
public void methodB() {
System.out.println("B");
}
}
interface IAB extends IA,IB{}
@Test
public void testProxy() {
IAB ab = new IAB() {
A a = new A();
B b = new B();
@Override
public void methodA() {
a.methodA();
}
@Override
public void methodB() {
b.methodB();
}
};
ab.methodA();
ab.methodB();
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…