プログラムに無限再帰があり、クラスにフィールドがあり、そのフィールドに同じクラスがあります。それらはシングルトンですが、これが構築しない原因ではありません。私がプログラムを書いたところで、私は実際に位相配列を削除することはできません。
abstract class Phase{
protected String phaseName;
protected char[] keys;
protected String[] commands;
protected Phase[] phases;
protected StringBuilder pattern;
}
class RemotePhase extends Phase{
private static RemotePhase remotePhase;
protected RemotePhase(){
phaseName="Remote.";
commands=new String[]{"Lock/unlock windows", "Toggle door", "Select dog menu"};
setPattern();
//Just below here starts an infinite loop
phases=new Phase[]{FixWindows.getFixWindows(), ToggleDoor.getToggleDoor(), SelectDogPhase.getSelectDogPhase()};
}
public static RemotePhase getRemotePhase(){
if(remotePhase==null){
remotePhase=new RemotePhase();
}
return remotePhase;
}
}
final class FixWindows extends Phase{
private static FixWindows windows;
private RemotePhase remotePhase;
private FixWindows(){
//execution keeps coming here as FixWindows object is never constructed
remotePhase=RemotePhase.getRemotePhase();
}
public static FixWindows getFixWindows(){
if(windows==null){
windows=new FixWindows();
}
return windows;
}
}
RemotePhase を静的クラスにして、FixWindows がそれをメンバーに使用しようとしましたが、抽象クラスの非静的メソッドをオーバーライドしようとして、非静的コンテキストで FixWindows からそれらを呼び出そうとすると、エラーが発生しました。ただし、RemotePhase を参照するためだけに追加のクラスを作成する必要があるため、静的にしないことを好みます。
ただし、これを機能させる方法はあります。ありがとう