casting - What is the cleanest way to compare an int with a potentially null Integer in Java? -


  मानचित्र & lt; स्ट्रिंग, पूर्णांक & gt; मीटर; मी = नया TreeMap & lt; स्ट्रिंग, पूर्णांक & gt; ();   

क्या m.get () शून्य है, जब शून्य पॉइंटर अपवाद से बचने के लिए निम्नलिखित कास्ट जोड़ना अच्छा अभ्यास है।

  System.out println (((पूर्णांक) 8) .equals (m.get ("null")); // गलत लौटता है   

वैकल्पिक रूप से एक पूर्व नल की जांच के साथ यह थोड़ा बदसूरत दिखने लगती है।

  System.out.println (m.contains (" शून्य ")! = नल & amp; एम.गेट (" नल ") बराबर (8));   

क्या यह लिखने का एक बेहतर तरीका है? धन्यवाद।

मैं जब भी संभव हो तो डालने से बचने की कोशिश करता हूं, इसलिए मैं निम्नलिखित का उपयोग करना चाहता हूं, जो भी मेरी राय में अच्छा लगता है:

  पूर्णांक.वल्यूओफ़ (8) .एक्वायल्स (m.get ("null"))    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -