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( ) ) ;
}
}
aW1wb3J0IGphdmEubGFuZy5yZWZsZWN0Lkludm9jYXRpb25IYW5kbGVyOwppbXBvcnQgamF2YS5sYW5nLnJlZmxlY3QuTWV0aG9kOwppbXBvcnQgamF2YS5sYW5nLnJlZmxlY3QuUHJveHk7CgpwdWJsaWMgY2xhc3MgTWFpbiB7CgogICAgaW50ZXJmYWNlIEZvbyB7IH0KCiAgICBpbnRlcmZhY2UgQmFyIHsgfQoKICAgIHN0YXRpYyBjbGFzcyBGb29CYXIxIGltcGxlbWVudHMgRm9vLCBCYXIgewogICAgICAgIHB1YmxpYyBTdHJpbmcgdG9TdHJpbmcoKSB7CiAgICAgICAgICAgIHJldHVybiAiRm9vQmFyMSI7CiAgICAgICAgfQogICAgfQoKICAgIHN0YXRpYyBjbGFzcyBGb29CYXIyIGltcGxlbWVudHMgRm9vLCBCYXIgewogICAgICAgIHB1YmxpYyBTdHJpbmcgdG9TdHJpbmcoKSB7CiAgICAgICAgICAgIHJldHVybiAiRm9vQmFyMiI7CiAgICAgICAgfQogICAgfQoKICAgIAoKICAgIHN0YXRpYyA8VCBleHRlbmRzIEZvbyAmIEJhcj4gVCBnZXRGb29CYXIxKCkgewogICAgICAgIHJldHVybiAoVCkgbmV3IEZvb0JhcjEoKTsKICAgIH0KCiAgICBzdGF0aWMgPFQgZXh0ZW5kcyBGb28gJiBCYXI+IFQgZ2V0Rm9vQmFyMigpIHsKICAgICAgICByZXR1cm4gKFQpIG5ldyBGb29CYXIyKCk7CiAgICB9CgogICAgc3RhdGljIDxUIGV4dGVuZHMgRm9vICYgQmFyPiBUIGdldEZvb0JhcigpIHsKICAgICAgICByZXR1cm4gKFQpIFByb3h5Lm5ld1Byb3h5SW5zdGFuY2UoCiAgICAgICAgICAgICAgICBGb28uY2xhc3MuZ2V0Q2xhc3NMb2FkZXIoKSwKICAgICAgICAgICAgICAgIG5ldyBDbGFzczw/PltdIHtGb28uY2xhc3MsIEJhci5jbGFzc30sCiAgICAgICAgICAgICAgICBuZXcgSW52b2NhdGlvbkhhbmRsZXIoKSB7CiAgICAgICAgICAgICAgICAgICAgcHVibGljIE9iamVjdCBpbnZva2UoT2JqZWN0IHByb3h5LCBNZXRob2QgbWV0aG9kLCBPYmplY3RbXSBhcmdzKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiAiUFJPWFkhISEiOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICApOwogICAgfQoKICAgIHN0YXRpYyA8VSBleHRlbmRzIEZvbyAmIEJhcj4gdm9pZCBzaG93KFUgdSkgewogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbih1KTsKICAgIH0KCiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CiAgICAgICAgc2hvdyhnZXRGb29CYXIoKSk7CiAgICAgICAgc2hvdyhnZXRGb29CYXIxKCkpOwogICAgICAgIHNob3coZ2V0Rm9vQmFyMigpKTsKICAgIH0KfQ==
compilation info
Main.java:50: type parameters of <T>T cannot be determined; no unique maximal instance exists for type variable T with upper bounds java.lang.Object,Main.Foo,Main.Bar
show(getFooBar());
^
Main.java:51: type parameters of <T>T cannot be determined; no unique maximal instance exists for type variable T with upper bounds java.lang.Object,Main.Foo,Main.Bar
show(getFooBar1());
^
Main.java:52: type parameters of <T>T cannot be determined; no unique maximal instance exists for type variable T with upper bounds java.lang.Object,Main.Foo,Main.Bar
show(getFooBar2());
^
Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
3 errors
stdout