第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

golang 有類似泛型 (java) 的東西嗎?

golang 有類似泛型 (java) 的東西嗎?

Go
湖上湖 2021-07-07 13:01:13
我想在 golang 上寫類似 CRUD 的東西。我看到像type CRUD interface {  Save(entity interface{})() // done  Update(entity interface{})() // done  Delete(entity interface{})() // done  All() []interface{} // problem is here}我有幾個(gè)模型結(jié)構(gòu)。type User struct {  Login string  Password string}type Comment struct {  UserId int64  Message string  CreatedAt int64}我有一些服務(wù):// Struct should implement interface CRUD and use instead of interface{} User structtype UserService struct {  Txn SomeStructForContext}func (rec *UserService) Save(entity interface{}) {  user := entity.(*model.User)  // TODO operation with user}// All the same with Update and Deletefunc (rec *UserService) All() ([]interface{}) {  // TODO: I can't convert User struct array for return }我希望,它會(huì)解釋什么問(wèn)題
查看完整描述

1 回答

?
不負(fù)相思意

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超10個(gè)贊

您正在嘗試轉(zhuǎn)換[]ConcreteType[]interface{},這并不隱式工作。

但是您可以轉(zhuǎn)換[]ConcreteTypeinterface{}然后將其轉(zhuǎn)換回[]ConcreteType.


查看完整回答
反對(duì) 回復(fù) 2021-07-19
  • 1 回答
  • 0 關(guān)注
  • 309 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)