Conditional Operator with and without ()
问题 I have run in to some weird thing when I want to print one of my objects (which is obviously not null). If I use this line: text.append("\n [ITEM ID]: " + (item == null ? (otherItem == null ? 0 : otherItem .getItems().get(i).getId()) : item .getItems().get(i).getId())); There is no null pointer exception if my item object is null . Of course this should be the excepted result. But if I use it without the () marks: text.append("\n [ITEM ID]: " + item == null ? (otherItem == null ? 0 :