Passing code as function arguments

后端 未结 6 1604
星月不相逢
星月不相逢 2021-01-23 22:56

I was reading a textbook and I was wondering how come the argument we pass to the function is neither a primitive or an user-defined instance of a class.

SwingU         


        
6条回答
  •  感动是毒
    2021-01-23 23:16

    The code inside SwingUtilities is something like this

    private Runnable runnable;
    
    private void invoke(){//called at some point from inside the runnable
         runable.run();
    }
    public void invokeLater(Runnable runnable){
         this.runnable=runnable;
    }
    

    These are called callbacks.

提交回复
热议问题