class Ideone {
A<ConcreteErrorHandler> a = new A<ConcreteErrorHandler>(new ConcreteErrorHandler());
a.m(); // Exception here!
}
public static class AbstractErrorHandler {
public void handle() {
}
}
public static class ConcreteErrorHandler extends AbstractErrorHandler {
public void handle() {
System.
out.
println("Concrete handler"); }
}
public static class A<T extends AbstractErrorHandler> {
T instance;
A(T instance) {
this.instance = instance;
}
public void m() {
instance.handle();
}
}
}
Y2xhc3MgSWRlb25lIHsKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHRocm93cyBqYXZhLmxhbmcuRXhjZXB0aW9uIHsKICAgICAgICBBPENvbmNyZXRlRXJyb3JIYW5kbGVyPiBhID0gbmV3IEE8Q29uY3JldGVFcnJvckhhbmRsZXI+KG5ldyBDb25jcmV0ZUVycm9ySGFuZGxlcigpKTsKICAgICAgICBhLm0oKTsgLy8gRXhjZXB0aW9uIGhlcmUhCiAgICB9CgogICAgcHVibGljIHN0YXRpYyBjbGFzcyBBYnN0cmFjdEVycm9ySGFuZGxlciB7CiAgICAgICAgcHVibGljIHZvaWQgaGFuZGxlKCkgewogICAgICAgICAgICB0aHJvdyBuZXcgVW5zdXBwb3J0ZWRPcGVyYXRpb25FeGNlcHRpb24oIk5vdCBpbXBsZW1lbnRlZCIpOwogICAgICAgIH0KICAgIH0KCiAgICBwdWJsaWMgc3RhdGljIGNsYXNzIENvbmNyZXRlRXJyb3JIYW5kbGVyIGV4dGVuZHMgQWJzdHJhY3RFcnJvckhhbmRsZXIgewogICAgICAgIHB1YmxpYyB2b2lkIGhhbmRsZSgpIHsKICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJDb25jcmV0ZSBoYW5kbGVyIik7CiAgICAgICAgfQogICAgfQoKICAgIHB1YmxpYyBzdGF0aWMgY2xhc3MgQTxUIGV4dGVuZHMgQWJzdHJhY3RFcnJvckhhbmRsZXI+IHsKCiAgICAgICAgVCBpbnN0YW5jZTsKCiAgICAgICAgQShUIGluc3RhbmNlKSB7CiAgICAgICAgICAgIHRoaXMuaW5zdGFuY2UgPSBpbnN0YW5jZTsKICAgICAgICB9CgogICAgICAgIHB1YmxpYyB2b2lkIG0oKSB7CiAgICAgICAgICAgIGluc3RhbmNlLmhhbmRsZSgpOwogICAgICAgIH0KICAgIH0KfQ==