[883] in java-interest

home help back first fref pref prev next nref lref last post

Re: mutual dependencies among public classes

daemon@ATHENA.MIT.EDU (Doug Lea)
Sun Aug 13 11:49:26 1995

Date: Sun, 13 Aug 1995 07:09:03 -0400
From: Doug Lea <dl@altair.cs.oswego.edu>
To: jpayne@starwave.com
CC: econsoft@wintermute.co.uk, java-interest@java.sun.com
In-reply-to: <9508111556.AA19466@flim.starwave.com> (jpayne@starwave.com)


> This statement is incorrect, unless I am confused.  You can have
> classes referring to each other, left and right, and it just works.
> They don't have to be in the same file or package.  The compiler just
> has to be able to find the other classes, which is why there is the
> convention that classes (public ones, anyway) are in files that match
> their class names.

Indeed it does just work. Sorry for the confusion.

Hoping to counteract my previous misinformation, here's a successful
example.  All of the right .class files are generated, without errors
or warnings when you place all of the following files in a
subdirectory/package `t813', and then compile with `javac
Tester.java'. (The use of a package here was just to verify that only
those files/.classes listed here were being used. The use of
interfaces was just to show that it works for interfaces as well.)

-- file InterfaceA.java:

  package t813;

  public interface InterfaceA {
    public void a1(InterfaceB b);
  }

-- file InterfaceA.java:

  package t813;

  public interface InterfaceB {
    public void b1(InterfaceA a);
  }

-- file ClassA.java:

  package t813;

  public class ClassA implements InterfaceA {
    public void a1(InterfaceB b) { System.out.println("a1"); }
  }

-- file ClassB.java:

  package t813;

  public class ClassB implements InterfaceB {
    public void b1(InterfaceA a) { a.a1(this); }
  }

-- file Tester.java

  package t813;

  public class Tester {
    static public void main(String args[]) {
      ClassA a = new ClassA();
      ClassB b = new ClassB();
      a.a1(b);
      b.b1(a);
    }
  }

-- 
Doug Lea | dl@cs.oswego.edu | dl@cat.syr.edu | 315-341-2688 | FAX 315-341-5424
Computer Science Dept, SUNY Oswego, Oswego, NY 13126 | http://g.oswego.edu/dl/
Also: Software Eng. Lab, NY CASE Center, Syracuse Univ, Syracuse NY 13244
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post