implicit_call_tearoffs
當使用物件作為函式時,明確地 tear-off call
方法。
詳細資訊
#務必 當指派給函式類型時,從物件明確地 tear off .call
方法。明確的 tear off 較少魔法。未來的語言版本可能會移除隱含的 call tear off。
不良範例
dart
class Callable {
void call() {}
}
void callIt(void Function() f) {
f();
}
callIt(Callable());
良好範例
dart
class Callable {
void call() {}
}
void callIt(void Function() f) {
f();
}
callIt(Callable().call);
啟用
#若要啟用 implicit_call_tearoffs
規則,請在您的 analysis_options.yaml
檔案中的 linter > rules 下新增 implicit_call_tearoffs
analysis_options.yaml
yaml
linter:
rules:
- implicit_call_tearoffs
如果您改為使用 YAML map 語法來設定 linter 規則,請在 linter > rules 下新增 implicit_call_tearoffs: true
analysis_options.yaml
yaml
linter:
rules:
implicit_call_tearoffs: true
除非另有說明,否則本網站上的文件反映 Dart 3.7.1 版本。頁面最後更新於 2025-03-07。 檢視原始碼 或回報問題。