I was given two of these line of code. What are the differences between two of these and which one is better for simple program.
public static < E > void swap(List< E > list, int i, int j);
vs
public static void swap(List<?> list, int i, int j);
>Solution :
public static < E > void swap(List< E > list, int i, int j);
Depends on generic class, sample
public class Test<E> {
public <E> swap(List<E> list, int i, int j) {
// your code
}
}
public class ExtendTest<Person> {
public Person swap(List<Person> list, int i, int j) {
// your code
}
}
public static void swap(List<?> list, int i, int j);
Can use with non-generic class, sample:
public class Test {
public List<?> swap(List<?> list, int i, int j) {
// your code
}
}