Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java using interface as a callback

I am trying to implement a callback procedure by having a class implement and interface, and then pass that class as an object (of the interface) to another class. However, I am receiving the error: "The constructor ClassB(TestMe) is undefined". I thought that I was doing this correctly, I don't know what I am doing wrong. Can someone please offer some advice? My code is below:

I have an interface:

public interface RequestResults {

     public void requestFailed(String message);

     public void requestSucceeded(String xml);

}

And I have a class that implements the interface:

public class TestMe implements RequestResults {

    public TestMe() {

        ClassB b = new ClassB(this);

    }

    public void requestFailed(String message) {
        // TODO Auto-generated method stub

    }

    public void requestSucceeded(String xml) {
        // TODO Auto-generated method stub

    }
}

Finally, I have a class that is instantiated in the prior class:

  public class ClassB {

    RequestResults results;

    public ClassB(RequestResults results) {

        this.results = results;

    }

}

Thanks!

like image 537
littleK Avatar asked Nov 03 '10 20:11

littleK


1 Answers

I've coded the whole thing on my side and everything compiled. Cleaning and compiling it afresh might help.

like image 76
Buhake Sindi Avatar answered Oct 19 '22 17:10

Buhake Sindi