首页 > 编程知识 正文

java调用其他类的方法,java 方法调用

时间:2023-05-06 14:18:48 阅读:11313 作者:2916

//给出了两个使用实例,第二种情况定义了前者为后者子类的类型公共配位方式

包明;

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 );

}

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。