Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何创建包含子对象的超类列表?_Java_List - Fatal编程技术网

Java 如何创建包含子对象的超类列表?

Java 如何创建包含子对象的超类列表?,java,list,Java,List,我试图编写一个列表,其中可以包含从同一个扩展而来的不同类。 我没有使用arraylist,而是自己创建列表,使用以下基本结构: public class L_Subjects { private Subject first; public L_Subjects(){ this.first=null; } //methods (add, delete, length, etc.) } public class Subject{ /

我试图编写一个列表,其中可以包含从同一个扩展而来的不同类。 我没有使用arraylist,而是自己创建列表,使用以下基本结构:

public class L_Subjects {

    private Subject first;

    public L_Subjects(){
        this.first=null;
    }

    //methods (add, delete, length, etc.)

}

public class Subject{

    //variables of the subject
    private subject next;

    public Subject(/*variables*/){
        //setting the parameters to each variable
        this.next=null;
    }

    //methods

}
因此,每个主题都通过指向它的“指针”链接到列表中的下一个主题。这些方法通过使用主题对象作为索引(index=index.getnext();)的循环遍历列表


但现在我想添加不同类型的主题,使用heritage,但没有每种类型主题的列表。我仍然想要一个包含所有主题的列表,其中包括扩展主题的不同类的不同对象。有没有什么方法可以在不严重修改我使用的基础结构的情况下做到这一点?也许下一步是空的?

您需要将列表的内容从列表的结构中分离出来。@ck分离是什么意思?