title: Cannot cast to an Extended Class in Java
body: <p>I looked around for a similar issue but couldn't find anything that matched it. </p>
  
  <p>I'm trying to extend the built-in JSONObject to add some functionality, like so:</p>
  
  <pre><code>public class MyJSONObject extends JSONObject {
  
      // Easily return an integer from a JSONObject, handling when the value is null.
      //
      public Integer getIntegerUnlessNull(String key) throws JSONException {
          String key_value = this.getString (key);
  
          if ( key_value.equals("null") ) {
              return null;
  
          } else {
              return Integer.parseInt( key_value );
          }
      }
  }
  </code></pre>
  
  <p>However, when I try to cast it, I get a <code>java.lang.ClassCastException</code> error: </p>
  
  <pre><code>private JSONArray    jsonClients;
          MyJSONObject clientJSONRecord;
  
  clientJSONRecord = (MyJSONObject) jsonClients.getJSONObject(0);
  </code></pre>
  
  <p>The full error message is:</p>
  
  <pre><code>java.lang.ClassCastException: org.json.JSONObject cannot be cast to com.insightemissions.trak.extensions.MyJSONObject
  </code></pre>
  
  <p>Any help?</p>
  
  <p>Cheers, </p>
  
  <p>JP</p>