Can't check if int is null
问题 I'm trying to use a dictionary. Whenever I want to check if an element is present in the dictionary, I do this: int value = results.get("aKeyThatMayOrMayNotBePresent"); if (value != null) // ... But then the compiler says I can't compare an int to a <nulltype> . What's the correct way to check for null in this case? 回答1: You're comparing a primitive value (int) to null. Since primitives cannot be null, you should use a corresponding object, such as Integer in this case. So, you should write