ZhangZhihui's Blog  

 

package main

import "fmt"

func main() {
    result1 := add(1, 2)
    fmt.Println(result1)

    result2 := add("abc", "def")
    fmt.Println(result2)
}

func add[T int | float64 | string](a, b T) T {
    return a + b
}

 

posted on 2026-03-19 10:04  ZhangZhihuiAAA  阅读(13)  评论(0)    收藏  举报