Code Fix

上級 › オートボクシングで起きる NullPointerException › パターン4

オートボクシングで起きる NullPointerException

Integerはnullを持てますが、演算時にintへ開封されます。

 1  public class Main {
 2      public static void main(String[] args) {
 3          Integer a = null;
 4          boolean condition = false;
 5          int result = condition ? 1 : ____________;
                                               ^
 6          System.out.println(result);
 7      }
 8  }
Exception in thread "main" java.lang.NullPointerExceptionexited with code 1

空欄を埋めてビルドを通す

広告
広告スロット(未設定)

オートボクシングで起きる NullPointerException

Map.getの戻り値の受け方を扱います。

このエラーの解説と類題をまとめて見る →

広告
広告スロット(未設定)