Null-aware function call?

后端 未结 1 1766
不思量自难忘°
不思量自难忘° 2021-01-14 00:18

Dart has some null-aware operators, i.e. it is possible to do

var obj;
obj?.foo(); // foo is only called if obj != null.

Is this also possi

1条回答
  •  迷失自我
    2021-01-14 00:48

    Form the docs:

    Dart is a true object-oriented language, so even functions are objects and have a type, Function.

    Apply the null aware ?. operator to the call method of function objects:

    typedef void SomeFunc();
    
    SomeFunc f = null;
    
    f?.call();
    

    0 讨论(0)
提交回复
热议问题