The difference is that you can use this special version for method chaining.
Check this sample program:
public class MyFoo {
public <T extends MyFoo> T foo(){
System.out.println("foo");
return (T) this;
}
static class MyBar extends MyFoo{
public <T extends MyBar> T bar(){
System.out.println("bar");
return (T) this;
}
}
public static void main(String[] args) {
final MyFoo foo = new MyFoo().foo();
final MyBar bar1 = new MyBar().foo();
final MyBar bar2 = new MyBar().bar();
}
}
The assignment of the bar1 variable is only possible because of the <T extends MyFoo>
, without it, there would have to be a cast:
final MyBar bar1 = (MyBar) new MyBar().foo();
Unfortunately, at least with Java 7, compiler inference ends here, so you can't do
new MyBar().foo().bar();