The following situation:
I have three classes A, B and C. A is some sort of parent which means A has a reference to the instance of B as well as C. B does not have a reference to the instance of C and C has no reference to the instance of B.
B has a Object (in this case a TextArea) which needs to be accessed by C. C has some text (as a result from some other methods) which should be added to the Object (TextArea) from B.
B should implement a public functional interface. My boss said I should be able to achieve my goal that way. Unfortunately I cannot ask him about hit because he went on vacation. He just left a note.
EDIT: Found the solution to my problem. The following works just fine.
Class A:
package de.test;
public class A {
static B b = new B();
static C c = new C();
private static void doSomething() {
c.setChangeString(b.changeString());
}
public static void main(String... args) {
doSomething();
c.changeText();
System.out.println(b.string);
}
}
Class B:
package de.test;
public class B {
@FunctionalInterface
public interface ChangeString {
void setString(String string);
}
String string = "nein";
public ChangeString changeString() {
return (string) -> this.string = string;
}
}
Class C:
package de.test;
import de.test.B.ChangeString;
public class C {
public ChangeString changeString;
public void changeText() {
this.changeString.setString("YES");
}
public void setChangeString(ChangeString changeString) {
this.changeString = changeString;
}
}