java callback mode

Often write js callback, js callback is very simple, direct transfer method name, but java method can not be passed as arguments

But you can pass a java object to write multiple methods in an object, and then passed as a parameter to the object in the future, it is the object where the method can be called at the appropriate time.

such as:

class Abc {
   public  void sayStart () { 
    System.out.println ( "started!" ); 
  } 
  public  void sayEnd () { 
    System.out.println ( "over!" ); 
  } 
}    

As argument:

public void test(Abc abc){
  abc.sayStart();
  .
  .
  .
  abc.sayEnd();
}

 

Guess you like

Origin www.cnblogs.com/LcxSummer/p/10975383.html