我想將一個帶有引數的函式分配給一個已經宣告的變數,這樣我就可以稍后執行它。
類似的東西:
void main() {
Function p;
p = print('1'); // should not execute;
p;
}
我怎么做?是否可以?
uj5u.com熱心網友回復:
你可以這樣做
void main() {
late Function p;
p = () {
print('1');
};
p(); // it will print 1
}
uj5u.com熱心網友回復:
void Function(Object? object) p;
p = print;
p.call('1');
uj5u.com熱心網友回復:
對于您提供的示例,您可以執行以下操作:
void main() {
Function p = (){print('1');};
}
現在您可以p()稍后呼叫以執行它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/391678.html
