below code fails with NullPointerException somehow and I am not sure why:
import java.util.*;
public class MyClass {
public static void main(String args[]) {
Long x = null;
Long test = (true) ? x : 0L; //Fails here with NullPointerException
}
}
However, if i replace x with null in conditional operation, it works
import java.util.*;
public class MyClass {
public static void main(String args[]) {
Long x = null;
Long test = (true) ? null : 0L; //WORKS - replaced x with null
}
}
Can anybody help me understand whats going on here? or is it java bug.