winderror.java

来自「think in java TIJ-3rd-edition-code.zip」· Java 代码 · 共 37 行

JAVA
37
字号
//: c07:WindError.java 
// Accidentally changing the interface.
import com.bruceeckel.simpletest.*;

class NoteX {
  public static final int
    MIDDLE_C = 0, C_SHARP = 1, C_FLAT = 2;
}

class InstrumentX {
  public void play(int NoteX) {
    System.out.println("InstrumentX.play()");
  }
}

class WindX extends InstrumentX {
  // OOPS! Changes the method interface:
  public void play(NoteX n) {
    System.out.println("WindX.play(NoteX n)");
  }
}

public class WindError {
  public static void tune(InstrumentX i) {
    // ...
    i.play(NoteX.MIDDLE_C);
  }
  public static void main(String[] args) {
    SimpleTest monitor =
      new SimpleTest("WindError");
    WindX flute = new WindX();
    tune(flute); // Not the desired behavior!
    monitor.expect(new String[] {
      "InstrumentX.play()"
    });
  }
} ///:~

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?