主题:[讨论]关于java泛型Generic types,怎样继承的?
假如要写一个类去执行名叫PTList的类,该怎样写?我不是要完整答案,我只想知道基本结构,真的不太懂泛型。。请高手帮帮忙..谢谢。。
public class Stage1BasicTestDriver {
private static void testList(PTList<Integer> list,String testCase) {
System.out.println("size of " + testCase + " is " + list.size());
}
public static void main(String[] args) {
String op = args[0];
PTList<Integer> list = new PTListImpl<Integer>();
if ( op.equals("new" ) ) testList(list,"new list");
}
}
---------------------------------------------------------
import java.util.Iterator;
public interface PTList<ElementType> extends ConstantPTList<ElementType> {
void add(ElementType newElement);
}
------------------------------------------------------
public interface ConstantPTList<ElementType> {
int size();
}
public class Stage1BasicTestDriver {
private static void testList(PTList<Integer> list,String testCase) {
System.out.println("size of " + testCase + " is " + list.size());
}
public static void main(String[] args) {
String op = args[0];
PTList<Integer> list = new PTListImpl<Integer>();
if ( op.equals("new" ) ) testList(list,"new list");
}
}
---------------------------------------------------------
import java.util.Iterator;
public interface PTList<ElementType> extends ConstantPTList<ElementType> {
void add(ElementType newElement);
}
------------------------------------------------------
public interface ConstantPTList<ElementType> {
int size();
}