I am confusing that if the following method are same? Are there any subtle differences?
Your advice are very appreciated.
method 1
public static double sumOfList(List<?> list) {}
method 2
public static <T> double sumOfList(List<T> list) {}
Inside the method you can use T
in second case .
You cannot in first case.
Consider this example
private static <T> void printList(List<T> list) {
for (T t: list) {
System.out.println(t);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With