import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class Main {

    interface Foo { }

    interface Bar { }

    static class FooBar1 implements Foo, Bar {
        public String toString() {
            return "FooBar1";
        }
    }

    static class FooBar2 implements Foo, Bar {
        public String toString() {
            return "FooBar2";
        }
    }

    

    static <T extends Foo & Bar> T getFooBar1() {
        return (T) new FooBar1();
    }

    static <T extends Foo & Bar> T getFooBar2() {
        return (T) new FooBar2();
    }

    static <T extends Foo & Bar> T getFooBar() {
        return (T) Proxy.newProxyInstance(
                Foo.class.getClassLoader(),
                new Class<?>[] {Foo.class, Bar.class},
                new InvocationHandler() {
                    public Object invoke(Object proxy, Method method, Object[] args) {
                        return "PROXY!!!";
                    }
                }
        );
    }

    static <U extends Foo & Bar> void show(U u) {
        System.out.println(u);
    }

    public static void main(String[] args) {
        show(getFooBar());
        show(getFooBar1());
        show(getFooBar2());
    }
}