संभव डुप्लिकेट:
Integer wrapper objects share the same instances only within the value 127?
How != and == operators work on Integers in Java?अप्रत्याशित परिणाम तुलना करते समय ints
मैं निम्नलिखित मामलों के साथ दो ints की तुलना करने की कोशिश की और मिला अप्रत्याशित परिणाम
जब मैंने follo किया था विंग, @@@ मुद्रित किया गया था।
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-the-value-127) और [नया इंटीजर बनाम valueOf] (http://stackoverflow.com/questions/2974561) और [जावा के ==] पर असंगत व्यवहार (http://stackoverflow.com/questions/1148805) और [इंटीजर रैपर ऑब्जेक्ट्स केवल 127 के भीतर समान उदाहरण साझा करते हैं?] (http://stackoverflow.com/questions/5117132) और ... –
यदि आप रुचि रखते हैं तो अधिक जानकारी http://vanillajava.blogspot.co।uk/2012/01/आश्चर्यजनक-परिणाम-autoboxing.html –