2016-09-19 24 views
0
public class Schedule { 

    private Set<Seance> schedule; 

    public Schedule(){} 

    public Schedule(??) { 
     super(); 
     // ?? 
    } 
} 

我需要一些這樣的:private Set<> schedule = new TreeSet<>();但我需要在構造函數中做到這一點,是因爲我想通過某種物體降神///這個對象附表我想添加到使用計劃對象MAP ...請幫忙。對不起,我的英語)如何與集字段和parametrs TreeSet中創建構造

回答

0

試試吧!

public Schedule(){ 
schedule = new TreeSet<Seance>(); 
} 

public Schedule(Set<Seance> schedule) { 
    super(); 
    this.schedule = schedule; 
} 
+0

是涼爽的,但我的條件:在現場我需要設置,並且在構造函數中,我需要新TreeSet的(); – Marian

+0

什麼都可以的:) 'public Sc​​hedule(TreeSet schedule1){ super(); this.schedule = schedule1; }' – Pat

+0

是的!!! tnx的人))) – Marian

0

您可以將TreeSet對象傳遞給Schedule構造函數。而且,因爲您需要對Seance排序,您需要使用SortedSet。您還需要在Seance類中執行Comparable或提供Comparator以進行排序。

public class Schedule { 
    private SortedSet<Seance> sortedSet; 
    public Schedule(SortedSet<Seance> sortedSet) { 
      this.sortedSet = sortedSet; 
    } 
}