How to link with jars
Bryce McKinlay
bryce@albatross.co.nz
Mon Dec 4 02:36:00 GMT 2000
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 ]
More information about the Java
mailing list