0

When I use jdk1.7 to run these code below, both of test1() and test2() cause null pointer excetpion.

But when I switch to jdk1.8, test1() prints null and test2() causes null pointer exception.

public static void test1() {
    Map<String, Boolean> m = new HashMap<>();
    Boolean b = true ? m.get("a") : false;
    System.out.println(b);
}

public static void test2() {
    Map<String, Boolean> m = new HashMap<>();
    Boolean a = m.get("a");
    Boolean b = true ? a : false;
    System.out.println(b);
}

Could you tell me what is the condition operator actually work in jdk1.7 and jdk1.8?

fatDuo
  • 23
  • 2

0 Answers0