Golang,变量,字符串类型

rtm*_*777 4 go

是否可以使用字符串中的类型创建变量?

示例:
 我有两种类型:

type FirstType struct {
    ...
}

type SecondType struct {
    ...
}

// also I have a string variable
var1 := "Second"
Run Code Online (Sandbox Code Playgroud)

我想用类型创建变量 - String value + "Type":

var variable = []var1+"Type" // slice of "SecondType"
Run Code Online (Sandbox Code Playgroud)

预期结果就像在这种情况下:

var variable = []SecondType
Run Code Online (Sandbox Code Playgroud)

谢谢!

fuz*_*fuz 7

这是不可能的.Go不提供创建静态未知类型的变量的功能.变量的类型始终是静态已知的.请考虑使用接口.