weird typecasting ((ClassPathXmlApplicationContext) context).close(); : <p>I am learning java and spring on the way, I have the following code for which I do not understand how typecasting works:</p>

<pre><code>public class App {

    public static void main(String[] args) {

        ApplicationContext context = new ClassPathXmlApplicationContext("com/voja/spring/test/beans/beans.xml");

        ((ClassPathXmlApplicationContext) context).close();

    }

}
</code></pre>

<p>So the following:</p>

<pre><code>((ClassPathXmlApplicationContext) context).close();
</code></pre>

<p>is what I don't get.</p>

<p>My thinking is that it should be like:</p>

<pre><code>(ClassPathXmlApplicationContext) context.close();
</code></pre>

<p>But that gives an error.</p>

<p>The way it is now it's how it's supposed to be, but I don't get how is the method invoked on it, and why is <code>(ClassPathXmlApplicationContext) context</code> inside brackets, and once again how can a method be appended to this?</p>
