泛型教程使用這個:type Number interface {
int64 | float64
}golang 中沒有所有整數和浮點類型的接口嗎?
1 回答

蕭十郎
TA貢獻1815條經驗 獲得超13個贊
您可以聲明一個集成了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 關注
- 96 瀏覽
添加回答
舉報
0/150
提交
取消