Java: forward class declarations in namespaces

How do I forward ads in Java?

I have two classes, each of which must call a method in the other, and they are both in different namespaces. For instance...

package one;

class A {
    public void foo() {
        B b = new B();
        b.bah();
    }
}

and

package two;

class B {
    public void bah() {
        A a = new A();
        a.foo();
    }
}

UPDATE

In Eclipse, when this code is encountered, a compile-time error "The loop was detected in the build path ..." will be displayed.

+3
source share
4 answers

Just import them. Java is much smarter than C ++ about these things.

+3
source

In Eclipse, when this code is encountered, a compile-time error "The loop was detected in the build path ..." will be displayed.

, Eclipse , Eclipse . Eclipse .

, Eclipse .

+1

, :

package one;

import two.B;

class A {
    public void foo() {
        new B().bah();
    }
}

:

package one;

class A {
    public void foo() {
        new two.B().bah();
    }
}

, , ( , ).

0

(.. , ). Eclipse .

...

> > Java > p > > >

0

Source: https://habr.com/ru/post/1736322/


All Articles