LoginSignup
0
1

More than 3 years have passed since last update.

[Java] コンパイルエラーと実行時エラーの分類メモ

Last updated at Posted at 2019-06-29

コンパイルエラーになるケースと実行時エラーになるケースの分類。

コンパイルエラーになるケース

ラムダ式の型の不一致

BiFunction<Integer, Double, Integer> function = (x, y) -> x + y;
function.apply(1, 2.5);

(int)(x + y) もしくは、 BiFunction<Integer, Double, Double> に修正する必要がある。

実行時になるケース

FileInputStreamでreset()を呼び出し

FileInputStreamはreset()を呼び出せるがサポートはしていない。子クラスのBufferedInputStreamでサポートされる。


new FileInputStream("src/a/a.txt").reset();
//=> java.io.IOException: mark/reset not supported

親クラスのInputStreamのreset()

public synchronized void reset() throws IOException {
        throw new IOException("mark/reset not supported");
    }

子クラスのBufferedInputStreamのreset()

public synchronized void reset() throws IOException {
        getBufIfOpen(); // Cause exception if closed
        if (markpos < 0)
            throw new IOException("Resetting to invalid mark");
        pos = markpos;
    }
0
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1