J
John_Woo
Hi,
I'm trying to understand the generic concept. The following confused
me:
public static void main(String arg[])
{
Object[] oa = new Object [10];
Collection<Object> co = new ArrayList<Object>();
String[] sa = new String[10];
Collection<String> cs = new ArrayList<String>();
method(sa, co); //1
method(oa, co); //2
method(oa,cs); // 3, compile error:
//<T>method(T[],java.util.Collection<T>) in Test cannot be applied to
// (java.lang.Object[],java.util.Collection<java.lang.String>)
// method(oa,cs);
}
static <T> void method(T[]e, Collection<T> c)
{ //do nothing }
The #2 is obvious, but why #1 is ok and #3 is wrong?
I'm trying to understand the generic concept. The following confused
me:
public static void main(String arg[])
{
Object[] oa = new Object [10];
Collection<Object> co = new ArrayList<Object>();
String[] sa = new String[10];
Collection<String> cs = new ArrayList<String>();
method(sa, co); //1
method(oa, co); //2
method(oa,cs); // 3, compile error:
//<T>method(T[],java.util.Collection<T>) in Test cannot be applied to
// (java.lang.Object[],java.util.Collection<java.lang.String>)
// method(oa,cs);
}
static <T> void method(T[]e, Collection<T> c)
{ //do nothing }
The #2 is obvious, but why #1 is ok and #3 is wrong?