01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package singleton.state;
public class S {
  private S() {}
  static private SState state;
  static {
    if ("linux".equals(System.getProperty("os.name"))) {
      state = new SLinux();
    } else {
      state = new SOther();
    }
  }
  static public int inc() { return state.inc(); }

  static private interface SState {
    public int inc();
  }
  static private class SLinux implements SState {
    private int i;
    public int inc() {return ++i;}
  }
  static private class SOther implements SState {
    private int i;
    public int inc() {return --i;}
  }
}