[3886] in java-interest

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

Mutually-referential classes ?

daemon@ATHENA.MIT.EDU (Bob Beck)
Thu Nov 30 19:35:50 1995

Date: Thu, 30 Nov 95 12:52 PST
To: java-interest@java.sun.com
From: Bob Beck <rbk@ibeam.jf.intel.com>

I saw some words on this in older postings, but no answer, so I'll ask again...

Suppose I have two classes that refer to each other (eg, ClassA and ClassB;
ClassA has a ClassB instance variable and invokes methods in that instance;
ClassB has methods that take ClassA arguments).  Both need to be public
classes (so they can be inherited from in different packages).  Can this be
done in Java?  The rules seem to be that public classes must be contained in
separate .java files; however, you can't import a class before it's compiled
and each class needs the other to be compiled first.  Is there some way
around this?

This is easy (and not uncommon) in C++ code, and it works fine in Smalltalk ...
--
Bob Beck                rbk@ibeam.intel.com     CompuServe: 71674,106
Intel Corporation       (503)264-8856           AOL: RDBeck

-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

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