I'm angry at Java 6 for letting this happen.
I realized this while writing a bug report for Mockito.
public class Wtf {
public static void main(String[] args) {
B b = wtfB();
System.out.println(b.foo());
System.out.println(((A) b).foo());
}
interface A {
Object foo();
}
interface B extends A {
@Override
String foo();
}
static B wtfB() {
return (B)
java.lang.reflect.Proxy.newProxyInstance(
ClassLoader.getSystemClassLoader(),
new Class[] { A.class, B.class },
new WtfInvocationHandler());
}
static class WtfInvocationHandler
implements java.lang.reflect.InvocationHandler {
@Override
public Object invoke(
Object proxy,
java.lang.reflect.Method method,
Object[] args) {
return method.getDeclaringClass()
.getSimpleName();
}
}
}