在Java

时间:2016-10-04 16:15:29

标签: java arrays collections

我有4个课程

public class Book {
private String title;
    private Autor[] autors;
    private Collection<Chapter> chapters;

    public Book(String title, Autor[] autors, Chapter[] chapters){
        this.title = title;
        this.autors = autors;
        this.chapters = new ArrayList<Chapter> ();
    }
}

在Book和Autor之间我有Agreggation,这就是为什么我在Book for Autor中使用数组

public class Autor {

    private String name;
    private Date dateBirth;
    private String afiliation;

    public Autor(String name, Date dateBirth, String afiliation){
        this.name = name;
        this.dateBirth = dateBirth;
        this.afiliation = afiliation;
    }
}

在Book和Chapters之间我有作文,这就是为什么我在Book中有一系列章节的原因

public class Chapter {

    private String title;
    private List <Section> sect;

    public Chapter(String title, List sect){
        this.title = title;
        this.sect = sect;
    }

    public String getTitle() {
        return title;
    }
}

章节和章节之间我也有作文,这就是为什么我有一个部分列表

public class Section{

    private String title;

    public Section(String title){
        this.title = title;
    }   
}

我现在的问题是当我想要实例化我不知道如何将参数作为集合,一系列autors提供

public class Test {

    public static void main(String[] args) {

        Autor[] autors = new Autor[]{
            autors[0] = new Autor("Simin Lebanon", new Date(23, 07, 1974), "Lincoln University"),
            autors[1] = new Autor("John Wayne Evald", new Date(15, 01, 1966), "Preston University"),
            autors[2] = new Autor("Ildiko Philipa", new Date(07, 11, 1989), "Minesota University")
        };

        Chapter[] chapters = new Chapter[2];
        chapters[0] = new Chapter("Introduction", section);

        Book eOROOS = new Book("Design Patterns Vol 1", autors[0], chapters[0]);
    }
}

Eclipse告诉我将构造函数Book(String,Autor [],Chapters [])更改为Book(String,Autor,Chapter),但我不想这样,因为我将失去agreggation和组合< / p>

0 个答案:

没有答案