」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 為什麼要投擲“不能將函數用作type在參數中”錯誤,我該如何修復?

為什麼要投擲“不能將函數用作type在參數中”錯誤,我該如何修復?

發佈於2025-03-22
瀏覽:278

Why Does Go Throw a

Understanding the Problem

The error message "cannot use function (type func()) as type in argument" means that the function you are trying to pass does not match the type required by the argument.在這種情況下,該參數期望MessageHandler接口的實現,該界面具有特定的函數簽名。

的函數必須確保您的函數符合消息HandsHandler接口的預期簽名:

示例:修改您的函數以與必需的簽名對齊:[&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& uppercaseHandler(MessagedEliveLivery) s.reply(messagetest {strings.toupper(md.message。(string))},md.delivery) 返回零,零 } func repeathandler(MD MessagedElivery)(接口{},錯誤){ s.reply(messagetest {strings.repeat(md.message。(string),5),5)},md.delivery) 返回零,零 } [&& && && && && &&華

最新教學 更多>

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3