I\'d like know why the following program throws a NPE
public static void main(String[] args) {
Integer testInteger = null;
String test = \"test\" + t
This is an example of the importance of understanding operator precedence.
You need the parentheses otherwise it is interpreted as follows:
String test = ("test" + testInteger) == null ? "(null)" : testInteger.toString();
See here for a list of operators and their precedence. Also note the warning at the top of that page:
Note: Use explicit parentheses when there is even the possibility of confusion.