# Friday, 04 November 2011
« Java Method Overriding Is FUBAR Part 3 o... | Main | Java Method Overriding Is FUBAR Part 5 o... »
Java Method Overriding Is FUBAR Part 4 of ∞

Another example of broken JDK 7 behavior:

package p1;

public class A
{
  { foo(); }
  void foo() {
    System.out.println("A.foo");
  }
  public static void main(String[] args) {
    new p3.F();
  }
}

package p2;

public class B extends p1.A
{
  { foo(); }
  void foo() {
    System.out.println("B.foo");
  }
}

package p2;

public class C extends p2.B
{
  { foo(); }
  void foo() {
    System.out.println("C.foo");
  }
}

package p3;

public class D extends p2.C
{
  { foo(); }
  void foo() {
    System.out.println("D.foo");
  }
}

package p1;

public class E extends p3.D
{
 { foo(); }
 void foo() {
   System.out.println("E.foo");
 }
}

package p3;

public class F extends p1.E
{
  { foo(); }
  void foo() {
    System.out.println("F.foo");
  }
}

To make this is a little clearer, here's a table view of the structure:

p1   p2   p3  
A    
  B  
  C  
    D
E    
    F

When you run it you get:

F.foo
C.foo
C.foo
F.foo
F.foo
F.foo

Not only is this not compliant with the spec, it just plain makes no sense.

Friday, 04 November 2011 08:32:31 (W. Europe Standard Time, UTC+01:00)  #    Comments [0]
Name
E-mail
Home page

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)

Answer:  
Comment (HTML not allowed)  

Live Comment Preview