가능한 중복 :
Integer wrapper objects share the same instances only within the value 127?
How != and == operators work on Integers in Java?예기치 않은 결과 때 비교의 int
나는 다음과 같은 경우에 두 가지의 int를 비교하기 위해 노력하고있어 예상치 못한 결과가
내가 그랬을 때 wing, @@@이 인쇄되었습니다.
class C { static Integer a = 127; static Integer b = 127; public static void main(String args[]){ if(a==b){ System.out.println("@@@"); } } }
@@@은 인쇄되지 않았습니다.
class C { static Integer a = 145; static Integer b = 145; public static void main(String args[]){ if(a==b){ System.out.println("@@@"); } } }
는 사람이 이유가 될 수 있는지 말해 줄 수.
사람이 ... [정수 래퍼 객체의 – Rookie
가능한 중복 단지 내에서 동일한 인스턴스를 공유 할 수 it..I이 할 수없는 오전 포맷 할 수 있다면 값 127?] (http://stackoverflow.com/questions/5117132/integer-wrapper-objects-share-the-same-instances-only-within-thevalue-127) 및 [New Integer vs valueOf] (http://stackoverflow.com/questions/2974561) 및 [Java의 일관되지 않은 동작 ==] (http://stackoverflow.com/questions/1148805) 및 [Integer 래퍼 개체가 값 127 내에있는 동일한 인스턴스를 공유합니까?] (http://stackoverflow.com/questions/5117132) 및 ... –
자세한 내용은 http://vanillajava.blogspot.co.uk/2012/01/surprising-results-of-autoboxing.html –