1
私は、ユーザーが並べ替えを選択できるさまざまな練習問題を表す2つの異なるクラスを作成しようとしています。 1つのクラスが選択された後、もう1つはオプションではなくなりました。このため、クラスの両方のクラスでそれに続くことができないArrayListを作成します。Javaの循環参照を避ける方法
問題は、これらのクラスが互いに従うことができないため、これらのクラスが構築されたときに無限ループになるということです。これを避ける方法はありますか?
PushPullLegsクラス
public class PushPullLegs extends SortingGroup implements Serializable{
public PushPullLegs(){
this.setName("Push,Pull,Legs");
this.addCantFollow(new MuscleGroup());
SortingCategory push = new SortingCategory("Push","PPL","Push");
this.addOption(push);
SortingCategory pull = new SortingCategory("Pull","PPL","Pull");
this.addOption(pull);
SortingCategory legs = new SortingCategory("Legs","PPL","Legs");
this.addOption(legs);
}
}
MuscleGroupクラス
public class MuscleGroup extends SortingGroup implements Serializable {
public MuscleGroup(){
this.addCantFollow(new PushPullLegs());
SortingCategory chest = new SortingCategory("Chest","Primary","Chest");
chest.addNewOptions(new ChestMovementPatterns());
this.addOption(chest);
SortingCategory triceps = new SortingCategory("Triceps","Primary","Triceps");
triceps.addNewOptions(new TricepMovementPatterns());
this.addOption(triceps);
SortingCategory lats = new SortingCategory("Lats","Primary","Lats");
this.addOption(lats);
SortingCategory quads = new SortingCategory("Quads","Primary","Quads");
this.addOption(quads);
SortingCategory hamstrings = new SortingCategory("Hamstrings","Primary","Hamstrings");
this.addOption(hamstrings);
}
}
をthis.addCantFollow(MuscleGroup.class); ' – Andreas
ありがとう、現在私のaddCantFollowメソッドのコンストラクタは: protected void addCantFollow(SortingGroup cf)。クラスを渡すときにcfパラメータをどのように変更する必要がありますか? – Mike
@Andreasだから私は、私が渡す.classファイルを格納できる変数のタイプを尋ねていると思いますか? – Mike