package main
import "fmt"
type Common interface {
int | uint | uint8
}
func main() {
result1 := add[int, int](3, 4)
fmt.Println(result1)
result2 := add(3, -4)
fmt.Println(result2)
}
func add[T1 Common, T2 int | uint | uint8](one T1, two T2) T1 {
result := one + T1(two)
return result
}
调用的是main.add[go.shape.int,go.shape.int]这个函数
对T1约束为int ,uint , uint8三种类型