I wonder if we use the general method only if the method is static? for non-static, you define a generic class, and you don't need it to be a universal method. It is right?
eg,
public class Example<E>{
public void doSomething(E [] arr){
for(E item : arr){
System.out.println(item);
}
}
public <E> doSomething(E [] arr){
for(E item : arr){
System.out.println(item);
}
}
}
whereas the compiler will force you to add a type parameter to make it universal if it is static.
public static <E> doSomething(E [] arr){
}
I'm not sure if I'm right or not.
source
share