What is the difference between calling the function without parentheses and with parentheses

前端 未结 5 933
甜味超标
甜味超标 2021-01-21 08:47

What is the difference between calling the function without parentheses and with parentheses on onPressed or Ontap?

I just know that void function can\'t be called with

5条回答
  •  梦谈多话
    2021-01-21 09:34

    Using parenthesis means you are giving the function an empty set of parameters to run. Using parenthesis with function name will execute the function if the function requires 0 parameters.

    On the other hand, Without parameters means you are just mentioning that function. Like,

    8;//Here I'm just mentioning 8. It's useless
    

    Example:

    void fun(){
      print('Func is running!');
    }
    
    void main(){
    func();//Here i wanna execute 'func'
    Function a = func;//Here i wanna assign 'func' to a
    }
    

    Output:

    Func is executing

提交回复
热议问题