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 {
return "FooBar1";
}
}
static class FooBar2 implements Foo, Bar {
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},
return "PROXY!!!";
}
}
);
}
static <U extends Foo & Bar> void show(U u) {
}
public static void main
(String[] args
) { show(getFooBar());
show(getFooBar1());
show(getFooBar2());
}
}
aW1wb3J0IGphdmEubGFuZy5yZWZsZWN0Lkludm9jYXRpb25IYW5kbGVyOwppbXBvcnQgamF2YS5sYW5nLnJlZmxlY3QuTWV0aG9kOwppbXBvcnQgamF2YS5sYW5nLnJlZmxlY3QuUHJveHk7CiAKcHVibGljIGNsYXNzIE1haW4gewogCiAgICBpbnRlcmZhY2UgRm9vIHsgfQogCiAgICBpbnRlcmZhY2UgQmFyIHsgfQogCiAgICBzdGF0aWMgY2xhc3MgRm9vQmFyMSBpbXBsZW1lbnRzIEZvbywgQmFyIHsKICAgICAgICBwdWJsaWMgU3RyaW5nIHRvU3RyaW5nKCkgewogICAgICAgICAgICByZXR1cm4gIkZvb0JhcjEiOwogICAgICAgIH0KICAgIH0KIAogICAgc3RhdGljIGNsYXNzIEZvb0JhcjIgaW1wbGVtZW50cyBGb28sIEJhciB7CiAgICAgICAgcHVibGljIFN0cmluZyB0b1N0cmluZygpIHsKICAgICAgICAgICAgcmV0dXJuICJGb29CYXIyIjsKICAgICAgICB9CiAgICB9CiAKICAgIAogCiAgICBzdGF0aWMgPFQgZXh0ZW5kcyBGb28gJiBCYXI+IFQgZ2V0Rm9vQmFyMSgpIHsKICAgICAgICByZXR1cm4gKFQpIG5ldyBGb29CYXIxKCk7CiAgICB9CiAKICAgIHN0YXRpYyA8VCBleHRlbmRzIEZvbyAmIEJhcj4gVCBnZXRGb29CYXIyKCkgewogICAgICAgIHJldHVybiAoVCkgbmV3IEZvb0JhcjIoKTsKICAgIH0KIAogICAgc3RhdGljIDxUIGV4dGVuZHMgRm9vICYgQmFyPiBUIGdldEZvb0JhcigpIHsKICAgICAgICByZXR1cm4gKFQpIFByb3h5Lm5ld1Byb3h5SW5zdGFuY2UoCiAgICAgICAgICAgICAgICBGb28uY2xhc3MuZ2V0Q2xhc3NMb2FkZXIoKSwKICAgICAgICAgICAgICAgIG5ldyBDbGFzczw/PltdIHtGb28uY2xhc3MsIEJhci5jbGFzc30sCiAgICAgICAgICAgICAgICBuZXcgSW52b2NhdGlvbkhhbmRsZXIoKSB7CiAgICAgICAgICAgICAgICAgICAgcHVibGljIE9iamVjdCBpbnZva2UoT2JqZWN0IHByb3h5LCBNZXRob2QgbWV0aG9kLCBPYmplY3RbXSBhcmdzKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiAiUFJPWFkhISEiOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICApOwogICAgfQogCiAgICBzdGF0aWMgPFUgZXh0ZW5kcyBGb28gJiBCYXI+IHZvaWQgc2hvdyhVIHUpIHsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4odSk7CiAgICB9CiAKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKICAgICAgICBzaG93KGdldEZvb0JhcigpKTsKICAgICAgICBzaG93KGdldEZvb0JhcjEoKSk7CiAgICAgICAgc2hvdyhnZXRGb29CYXIyKCkpOwogICAgfQp9