# 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]