The concrete implementation is to define the interface in the class, and pass in the parameters in the implementation method of the interface (also can not pass).
In the calling class, pass in the newly created interface and implement the method that is not implemented.
public class Callbackclass {//pass in the appropriate interface as parameter public void Huidiao (final rundate rundate) {//Use thread instead of system event new thread () {int i = 0;@ overridepublic void Run () {super.run (); while (true) {i++;//incoming callback parameter Rundate.hui ("+ i + " times callback parameter!) "); Try{sleep (5000);} catch (Interruptedexception e) {e.printstacktrace ();}}}}. Start ();} Define interface public interface rundate{public void Hui (String str);}}To pass in the interface parameters in the main function:
public class Test {public static void main (String [] args) {Callbackclass callback = new Callbackclass (); Callback.huidiao (n EW callbackclass.rundate () {@Overridepublic void Hui (String str) {System.out.println (str);}});}}An interface callback is also used in the next custom ListView.
Android callback mechanism instance!