import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Test {
public static GeneralBean makeSure(int m, int n, List A) {
GeneralBean result = null;
for (Iterator iterator = A.iterator(); iterator.hasNext();) {
GeneralBean A1 = (GeneralBean) iterator.next();
if (A1.getM() == m && A1.getN() == n) {
result = A1;
}
}
return result;
}
public static void main(String[] args) {
GeneralBean A1 = new GeneralBean(1, 2);
GeneralBean A2 = new GeneralBean(3, 4);
ArrayList listA = new ArrayList();
listA.add(A1);
listA.add(A2);
// 这就是你要返回的对象
GeneralBean resultObject = makeSure(1, 2 , listA);
}
}
class GeneralBean {
private int m;
private int n;
public GeneralBean (int m, int n) {
this.m = m;
this.n = n;
}
public int getM() {
return m;
}
public void setM(int m) {
this.m = m;
}
public int getN() {
return n;
}
public void setN(int n) {
this.n = n;
}
}
GeneralBean A = makeSure(1,2,listA);
最好使用范型,容易,安全!
没有明白你的意思……