ションボリ

久しぶりにすんごいの見つけた。

public class Hoge extends MIDlet implements CommandListener, Runnable {
    private Command exitCommand  = new Command("Exit", Command.EXIT, 2);
    private Command getCommand = new Command("Get", Command.SCREEN, 1);
    private Command postCommand = new Command("Post", Command.SCREEN, 1);

    private Command currentCommand;
    private Thread commandThread;

    public void destroyApp(boolean unconditional) {
    }
    private void readContents(String request) {
        // ファンタジックなコードはおして知るべし。
    }
    public void commandAction(Command c, Displayable s) {
        synchronized (this) {
            if (commandThread != null) {
                return;
            }

            currentCommand = c;
            commandThread = new Thread(this);
            commandThread.start();
        }
    }

    public void run() {
        if (currentCommand == exitCommand) {
            destroyApp(false);
            notifyDestroyed();
        } else if (currentCommand == getCommand) {
            readContents(HttpConnection.GET);
        } else if (currentCommand == postCommand) {
            readContents(HttpConnection.POST);
        } else ・・・・・

        synchronized (this) {
            commandThread = null;
        }
    }
}

まさか、Commandって名前のクラスの参照で分岐するとはおもわなんだ。
カッとなって書いてしもうた。
ちなみに、readContentsと言うメソッドの中では、
ヒープに対する参照はありません。
この環境は、スタックがスレッドセーフじゃ無いんだろうか……。
だとしたら恐ろしい事だ…。