Accessing a class with the exact same name
<p>I have a tricky question and I'm not sure if it is even possible in Java. I'm in the following 
situation:</p>

<p>I got a class A that uses another class, let's call it B. Now, I'm trying to write a third class (and I don't call it C), I call it B again (to be sure which class 'B' I mean, I will call it B1 and B2 in the rest of this post, ok?). All three classes resides in three different JAR-files. So far, so good. </p>

<p>Normaly, class A finds class B(1) on the classpath and will use it. But now I'm putting the JAR-file that contains B(2) at the very beginning of the classpath, so class A will find this class instead of the old one. So my class B(2) can act like the old class B(1) (which is a library in reality, that I can't customize in any other way. that's why I am doing that...).</p>

<p><strong>And here comes my problem:</strong> In my class B(2) I want to load the real class B(1) and use it. I can do this so far by using reflection. I can even invoke methods via reflection, but I can't cast an instance of the loaded class to B reference. Here is the exception:</p>

<pre><code>java.lang.ClassCastException: my.a.ClassB incompatible with my.a.ClassB
</code></pre>

<p>Has anybody an idea how I can use class B(1) in class B(2)? I am happy with any workarround...</p>

<p>Thanx, Thomas.</p>
