This is the mail archive of the java-discuss@sources.redhat.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: How to link with jars


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 ]



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]