Saturday, December 22, 2012

JDK 7 weirdness !

This is completely unintutive behavior in JDK 7.
I am sure the language theorist's will have some reason why it makes perfect sense, but as a programmer, it is confusing and unintutive.

Consider this simple class :
public class Jdk7Bug {

  private final int value;
  public Jdk7Bug(int value){
    this.value = value;
  }
  public static <C extends Jdk7Bug> void bug(C instance){
    System.out.println(instance.value);
  }


  public static <C extends Jdk7Bug> void works(C instance){
    Jdk7Bug val = instance;
    System.out.println(val.value);
  }
}

As you guessed it, the method 'bug' will fail with compile error in jdk7 (not in 6).
Generics is complicated enough without introducing weirdnesses like this, sigh ...

1 Comments:

Anonymous Rajat said...

Hi Mridul,

What email address can you be reached at?

Thanks.

1/13/2013 11:45:00 PM  

Post a Comment

<< Home