Yesterday's JDK 7u65 and 8u11 updates changed method overriding yet again and, of course, it is still broken.
Take this example:
package pkg1;public class A { { foo(); } void foo() { System.out.println("A.foo"); }} package pkg2;public class B extends pkg1.A { { foo(); } void foo() { System.out.println("B.foo"); }} package pkg1;public class C extends pkg2.B { { foo(); } void foo() { System.out.println("C.foo"); }} package pkg2;public class D extends pkg1.C { { foo(); } void foo() { System.out.println("D.foo"); }} public class test { public static void main(String[] args) { new pkg2.D(); }}
package pkg1;public class A { { foo(); } void foo() { System.out.println("A.foo"); }}
package pkg2;public class B extends pkg1.A { { foo(); } void foo() { System.out.println("B.foo"); }}
package pkg1;public class C extends pkg2.B { { foo(); } void foo() { System.out.println("C.foo"); }}
package pkg2;public class D extends pkg1.C { { foo(); } void foo() { System.out.println("D.foo"); }}
public class test { public static void main(String[] args) { new pkg2.D(); }}
Running this with JDK 8u5 yields:
D.fooD.fooD.fooD.foo
Which is, of course, wrong. In yesterday's updates they tried to fix this, but only partially succeeded:
D.fooD.fooC.fooD.foo
The sensible output would be:
C.fooD.fooC.fooD.foo
Remember Me
I apologize for the lameness of this, but the comment spam was driving me nuts. In order to be able to post a comment, you need to answer a simple question. Hopefully this question is easy enough not to annoy serious commenters, but hard enough to keep the spammers away.
Anti-Spam Question: What method on java.lang.System returns an object's original hashcode (i.e. the one that would be returned by java.lang.Object.hashCode() if it wasn't overridden)? (case is significant)
Powered by: newtelligence dasBlog 2.3.12105.0
© Copyright 2021, Jeroen Frijters
E-mail