Calendar 2023-01-24
Category category.notes
Language en

Strange NPE in Java ternary condition

One day my coworker sent me a code snippet with a simple question “What will be written in test2 variable?”:

1
2
Boolean test = null;
Boolean test2 = (true) ? test : false;