whats the difference between
public static <T> double sums(Collection<T extends Number> numbers) {}
and this
public static <T extends Number> double sums(Collection<T> numbers) {}
and this
public static double sums(Collection<? extends Number> numbers) {}
and this
public static <T> double sums(Collection<? extends Number> numbers) {}
i get that we mention type parameter <T>
before return type if we are using generics for only one method.and we can use the type parameter T here since its declared as classes type parameter(public class generics<T extends Integer >{}
). and i dont quite understand the difference between them. especially first and last.
im getting compile error on first statement, and no error on last statement. why i need to use ?
wildcard at first statement ? and may i know how having static keyword affects this method declaration?
edit: Im not using the type inside method so type parameter <T>
or <?>
should be functionally same. im using only one parameterized type argument which according to this post should be same even if we use wildcards there but im getting compile error when i use type parameter .