とインスタンスの建設は、私はルートのArrayList
を受け取るコンストラクタを持つ:受信routes
が空の場合防ぐ無効な引数
public Voo(ArrayList<Routes> routes, LocalDateTime dateTime, Duration duration) {
if (routes.isEmpty()) {
}
this.routes = routes;
this.dateTime = dateTime;
this.duration = duration;
this.status = Status.CONFIRMED;
}
にはどうすればVoo
のインスタンスを返すからコンストラクタを防ぐことができますか?
List.isEmpty()は、リストが空であるかどうかを確認するためのOK方法のようです。あなたの質問は何ですか? –
例外をスローします(例: 'throw new IllegalArgumentException(" rotasは空ではないかもしれません "); – Andreas
@TimBiegeleisenが言及したものの上にヌルチェックを追加します。 –