引用
public class NewClass {
public List test() {
return new ArrayList();
}
public static void main(String[] args) {
NewClass nc = new NewClass();
nc.test().add("aaa");//这里只能是String
}
}
这个方法完全可以满足你...
如果你定要那样~ 只有BT版本的啦~~
package org.test.jy;
/**
*
* @author Administrator
*/
public interface List extends java.util.List {
}
package org.test.jy;
/**
*
* @author Administrator
*/
public class ArrayList extends java.util.ArrayList
implements org.test.jy.List{
}
package org.test.jy;
/**
*
* @author Administrator
*/
public class JyTest {
private String name;
private String sex;
public JyTest(String name, String sex) {
this.name = name;
this.sex = sex;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
package org.test.jy;
/**
*
* @author yangtao309
*/
public class Test {
public static void main(String[] args) {
List list = new ArrayList();
list.add(new JyTest("test1", "male"));
list.add(new JyTest("test2", "female"));
list.add(new JyTest("test3", "female"));
list.add(new JyTest("test4", "male"));
list.add(new JyTest("test5", "male"));
for(JyTest jt:list) {
System.out.println("---" + jt.getName());
}
}
}
呵呵~
2008年12月12日 16:47