I have a generic:

public class Gen<T> { private T value; public T getValue() { return value; } } 

and some method:

 public void someMethod(Gen<?> gen) { System.out.println(gen.getValue()); } 

Will there be any difference if the parameter of the method someMethod is of type Gen instead of Gen<?> ?

I understand that a metacharacter argument can make extends or super .

I correctly understood that Gen is a way to solve problems of legacy code?

    1 answer 1

    In this case, there is no difference.

    The difference would exist if Gen had a method that accepts T :

     public void setValue(T value) { this.value = value; } 

    On Gen setValue can be performed, but on Gen<?> is impossible.

    Wildcard (wildcard) is used to set restrictions on the use of a generic class. Methods that can be performed with the Gen<?> Class can be performed for any Gen<T> without type errors.

    More details: