Go 还没有像 C# 或 Java 这样的泛型。它确实有一个空接口(interface{})如果我理解正确,以下是我认为可以回答您的问题的代码:包主import ( "fmt" "reflect")type generic interface{} // you don't have to call the type generic, you can call it Xfunc main() { n := test(10) // I happen to pass an int fmt.Println(n)}func test(arg generic) generic { // do something with arg result := arg.(int) * 2 // check that the result is the same data type as arg if reflect.TypeOf(arg) != reflect.TypeOf(result) { panic("type mismatch") } return result;}