是否可以使用字符串中的类型创建变量?
示例:
我有两种类型:
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)
谢谢!
| 归档时间: |
|
| 查看次数: |
580 次 |
| 最近记录: |