This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

class dependency problem.

 
Gene Woo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, there.
I am working on project that has many objects that have cross dependency problem, for example. A calls B and B class A. As a result, many objects can't compile if they are not in the same package. is there a way where I can get the classes to compile without change many lines of code. for example:
------ A.java ------
package example1;
public class A {

public void printB()
{
System.out.println("In printB: ");
B b = new B();
b.printA();


}
public static void main(String args)
{
A a = new A();
a.printB();
B b = new B();
b.printA();

}

}
--------- B.java ------------
package example2;

public class B {

public void printA()
{
System.out.println("In printA: ");
A a = new A();
a.printB();


}
}

-----------------------------------------
 
expired user
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose that u have to import the packages inorder to access the class and in turn the methods defined in those classes. Without importing Java doesn't know anything about the class A or B, in your case.
Try with this
import package.class;
import package.*;
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic