代码之家  ›  专栏  ›  技术社区  ›  learningUser

为什么对多态性使用回调方法

  •  1
  • learningUser  · 技术社区  · 9 年前

    public interface CallBack{
      void executeforConn();
    }
    
    abstract class CallbackImpl implements Callback {     
      void executeforConn(){
        executeStatements();
      }
    
      abstract void executeStatements();
    }
    

    在调用者中调用回调。

    new CallbackImpl{
      @Override
      executeStatements(){
        //extend the method
      }
    }
    
    Callback callback = new CallbackImpl();
    callback.executeforConn();
    

    1 回复  |  直到 9 年前
        1
  •  0
  •   Stephen C    9 年前

    有关回调的目的和使用的更详细解释,请阅读 Wikipedia article

    为什么对多态性使用回调方法

    属于 多态性;e、 g.一个回调API,具有多个实现不同行为的实现。