Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Generics - are these two method declarations equivalent?

Tags:

java

generics

Given some class SomeBaseClass, are these two method declarations equivalent?

public <T extends SomeBaseClass> void myMethod(Class<T> clz)

and

public void myMethod(Class<? extends SomeBaseClass> clz)
like image 556
Udo Avatar asked Apr 20 '11 13:04

Udo


1 Answers

For the caller: yes, they are equivalent.

For the code inside the method: no.

The difference is that within the code of the first example you can use the type T (for example to hold an object created by clz.newInstance()), while in the second you can't.

like image 124
Joachim Sauer Avatar answered Oct 11 '22 23:10

Joachim Sauer