title: Why cast to an interface instead of casting to a class java?
body: <p>I have come across some java classes used in the spring framework. First, there is the beans in the applicationContext.xml</p>
  
  <pre><code>&lt;bean id="someBean" parent="txProxyTemplate"&gt;
      &lt;property name="target"&gt;
          &lt;bean class="path.to.bean.impl.SomeBeanImpl"&gt;
              ...
          &lt;/bean&gt;
  ...
  &lt;/bean&gt;
  </code></pre>
  
  <p>And I have the interface <code>ISomeBean</code>, and its implementation <code>SomeBeanImpl</code>
  Then, I have another class which uses ISomeBean.</p>
  
  <pre><code>public class SomeOtherClass {
    ...
      public function doStuff() {
          ...
          ApplicationContext ctx;
          SomeBean theBean = (SomeBean) ctx.getBean; 
     }
  }
  </code></pre>
  
  <p>I want to know why do we cast to an interface instead of casting to the class.</p>