Casting base type with Java
<p>Say I have a base class:</p>

<pre><code>abstract class TheBase {}

class Foo extends TheBase {}
class Bar extends TheBase {}
</code></pre>

<p>And I want to "cast" the base object into this type:</p>

<pre><code>TheBase obj = getFromSomewhere();

Foo foo = obj.asA(Foo.class);

Bar bar = obj.asA(Bar.class);
</code></pre>

<p><code>asA</code> will throw an exception I have defined like: <code>CustomCannotCastException()</code></p>

<p>Is this possible?</p>
