泛型教程使用這個(gè):type Number interface {
int64 | float64
}golang 中沒(méi)有所有整數(shù)和浮點(diǎn)類型的接口嗎?
1 回答

蕭十郎
TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超13個(gè)贊
您可以聲明一個(gè)集成了constraints.Floatand的新類型約束constraints.Integer。
// Number is a custom type set of constraints extending the Float and Integer type set from the experimental constraints package.
type Number interface {
constraints.Float | constraints.Integer
}
- 1 回答
- 0 關(guān)注
- 100 瀏覽
添加回答
舉報(bào)
0/150
提交
取消