//给出了两个使用实例,第二种情况定义了前者为后者子类的类型公共配位方式
包明;
import java.util.ArrayList;
import java.util.Collection;
公共类通用操作系统{
staticvoidfromarraytocollection (twmdtka,Collection c )。
for(to:a ) {
c .添加(o );
}
}
publicstaticvoidmain (字符串wmdtkargs ) {
//todo自动- generated method stub
//T stand for Object
Objectwmdtk oa=new Object[100];
Collection co=new ArrayList (;
fromarraytocollection(OA,co );
//T stand for Number
Integerwmdtk ia=new Integer[100];
Floatwmdtk fa=new Float[100];
Collection cn=new ArrayList (;
fromarraytocollection(ia、cn;
fromarraytocollection(fa、cn;
}
}
包明;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
公共类通用操作系统{
staticvoidfromarraytocollection (collectionextendstfrom,
Collection to ) {
for(tele:from ) {
待办事项(ele;
}
}
publicstaticvoidmain (字符串wmdtkargs ) {
List ao=new ArrayList (;
List as=new ArrayList (;
//string is subclass of object
fromarraytocollection(as,ao );
}
}