Difference between void foo(T t) and void foo(A a)

Say A is an interface. What is the difference between

public <T extends A> void foo(T t) { ... }


public void foo(A a) { ...}



Not much.

On the other hand, consider this method:

public <T extends A> T transform(T t);

And caller code:

class B implements A { ... }
B result = transform(new B(...));

It wouldn’t be possible (above wouldn’t compile, as compiler would force you to declare result type as A) had you declared method as

public A transform(A a)

Leave a Reply

Your email address will not be published. Required fields are marked *