The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Java Handles cyclic dependency automatically

Posted by Kishori Sharan on January 08, 2001 at 10:32 AM

But in Java such kind of cyclic dependecies are handled automatically by compiler.Let us take an example

public class Temp1 {

public static void main ( String[] args ) {
Temp2 tt = new Temp2 ( ) ;

public class Temp2 {

public static void main ( String[] args ) {
Temp1 tt = new Temp1 ( ) ;

In the above case Temp1 uses Temp2 and Temp2 uses Temp1. So just create two classes and save them in two different .java file ( or you may want to create one file ) . If you compile either one Temp1 or Temp2 both classes will be compiled automatically. You can verify it by looking at .class files generated.
This has been clearly mentioned in Java Language Specification that if there is cyclic dependency like this then Java Compiler will manage to compile the two classes simultaneously.
So I think you don't need to worry about it.



Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us