mirror of
https://github.com/MADTeacher/go_basics.git
synced 2025-11-23 21:34:47 +02:00
17 lines
307 B
Go
17 lines
307 B
Go
|
|
package main
|
||
|
|
|
||
|
|
import "fmt"
|
||
|
|
|
||
|
|
type MyInt int
|
||
|
|
|
||
|
|
func Sum[T int | float64 | string](a, b T) T {
|
||
|
|
return a + b
|
||
|
|
}
|
||
|
|
|
||
|
|
func main() {
|
||
|
|
var value1, value2 MyInt = 34, 22
|
||
|
|
fmt.Println(Sum(value1, value2))
|
||
|
|
// MyInt does not implement int|float64|string
|
||
|
|
// (possibly missing ~ for int in constraint int|float64|string)
|
||
|
|
}
|