title: How could this Java method be improved?
body: <p>I am parsing XML files and I have several methods similar to:</p>
  
  <pre><code>public static Integer getInteger(Object integer) {
    if (integer == null) {
       return 0;
    }
  
    try {
       return Integer.parseInt(integer.toString(), 10);
    } catch (Exception ex) {
       return 0;
    }
  }
  </code></pre>
  
  <p>So basically, you pass an object in with the assumption of converting it to an Integer (I also have versions for Float, etc).</p>
  
  <p>This seems to work well but being a Java newbie, I was wondering how you would improve it.  I am especially interesting in the boxing/unboxing aspect (at least, from a C# developer's perspective).</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Sorry, I wasn't clear to what goes into the method.  Yes, it's for an XML file now so it's always a string. But the string could be empty or maybe even null.  I guess I wanted to always return a 0 if there was an error of any kind.</p>