Integer == int allowed in java
问题 I was wondering if java automatically turns a Integer into an int when comparing to an int? Or will the == try and compare references on primitives? Is this always true or do I need to do i.intValue()==2 ? Integer i = Integer.valueOf(2); if (i==2){ //always? } 回答1: Yes, when comparing int using == arguments will be unboxed if necessary. Relevant section from the Java Language Specification: 15.21.1 Numerical Equality Operators == and != If the operands of an equality operator are both of