title: Adding a Convienience Method to Existing Class (Class Cast Exception)
body: <p>Java/Android noob here (Still) I hoped you could help.</p>
  
  <p>I was trying to add a small convenience method to get the number of time that has passed rather than the number of time since EPOCH.</p>
  
  <p>So I tried to do this:</p>
  
  <pre><code>public class EasyLocation extends android.location.Location {
  
      ...
  
      public long getElapsedTime() {
          return getTime() - System.currentTimeMillis();
      }
  }
  </code></pre>
  
  <p>However when I tried to use it like in the code below which casts it to my Location class. I got a class cast exception. I've read up on it and I fully understand why it doesn't work. That's not the issue.</p>
  
  <p>The issue is: it's not a train smash but I would like to have what is returned to have my method on it to make the rest of my code a bit cleaner. I can't figure out a way around it. Any ideas on how to do that? </p>
  
  <pre><code>lastNetworkLocation = (EasyLocation) locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
  </code></pre>
  
  <p>Thanks,</p>
  
  <p>Gerard.</p>