Hi,
In the following code
import java.util.Collection;
import java.util.ArrayList;
public class TestGenerics {
static <T> void fromArrayToCollection(T[] a,Collection<T> c){
for(T b:a)
c.add(b);
System.out.println("Added");
}
static <T> void fromCollectionToCollection(Collection<T> a,Collection<T> c){
System.out.println("Added");
}
/**
* @param args
*/
public static void main(
String[] args) {
// TODO Auto-generated method stub
Integer[] oa = new Integer[10];
Collection<Number> cn= new ArrayList<Number>();
Collection<Integer> ci= new ArrayList<Integer>();
fromArrayToCollection(oa,cn);
fromCollectionToCollection(ci, cn);
}
}
why am I getting compilation error in fromCollectionToCollection(ci, cn); method but not in fromArrayToCollection(oa,cn);
However in both cases the T type being given is different.But in one case it works and in other it does not.
thanks in advance
mayur