This is the mail archive of the
java-discuss@sources.redhat.com
mailing list for the Java project.
Re: How to link with jars
- To: Torsten Rüger <torsten dot rueger at firsthop dot com>, java-discuss at sources dot redhat dot com
- Subject: Re: How to link with jars
- From: Bryce McKinlay <bryce at albatross dot co dot nz>
- Date: Mon, 04 Dec 2000 23:37:17 +1300
- References: <3A2B6365.D1251F5B@firsthop.com> <3A2B6626.5DC04350@albatross.co.nz> <3A2B6F68.4BE2032B@firsthop.com>
Torsten Rüger wrote:
> > Well, you can't have native code depend directly on interpreted code. You
> > need to use Class.forName().
>
> Say I have class A and B, A depending on B. If I compile A, but leave B as a
> class file:
>
> You are saying it will only work if A loads B using Class.forName. So it
> will not work if B is a plain member variable, right?
Right.
> Ok, to get it so Class.forName is used, I would have to use interfaces. A
> would rely on interface C and B would implement C.
Yes, B can be interpreted as long as your native code doesn't actually refer to
it. So you can have something like (not actually tested, but you get the idea):
abstract class C /* native, could also be an interface... */
{
void blah();
}
class B /* interpreted */
{
void blah()
{
System.out.println ("I am a class file");
}
}
/* native class */
public class A
{
public static void main(String[] args)
{
Class b_cl = Class.forName("B");
C c = b_cl.newInstance();
c.blah();
}
}
regards
[ bryce ]