title: Java upcasting and downcasting by interfaces
body: <p>This is probably a dumb question but I need to know.
  I have an interface as </p>
  
  <pre><code>import com.amazonaws.services.dynamodbv2.AmazonDynamoDBAsync;
  
  public interface AsyncClient extends AmazonDynamoDBAsync{
  
  }
  </code></pre>
  
  <p>And I have a <strong>ClientCreator</strong> class which has the method </p>
  
  <pre><code>import com.company.clients.AsyncClient;
  public class ClientCreator {
          public static AsyncClient getAsyncClient() throws FileNotFoundException, IllegalArgumentException, IOException{
              AmazonDynamoDBAsync client = new AmazonDynamoDBAsyncClient(getCredentials());
              client.setRegion(getRegion());
              return (AsyncClient)client;
          }
          .
          .
          .
  </code></pre>
  
  <p>Here <strong>AmazonDynamoDBAsyncClient implements AmazonDynamoDBAsync</strong> and <strong>AsyncClient extends AmazonDynamoDBAsync</strong>, but this code would not work and throws</p>
  
  <blockquote>
    <p>com.amazonaws.services.dynamodbv2.AmazonDynamoDBAsyncClient cannot be
    cast to com.company.clients.AsyncClient</p>
  </blockquote>
  
  <p>but <strong>why</strong>?</p>