Golang, variable with type from string

前端 未结 1 1068
悲&欢浪女
悲&欢浪女 2021-01-19 06:43

Is it possible to create variable with type from string?

Example:
 I have two types:

type FirstType struct {
    ...
}

type SecondType stru         


        
1条回答
  •  抹茶落季
    2021-01-19 07:37

    This is not possible. Go does not provide functionality to create variables of types that are not known statically. The type of a variable is always known statically. Consider using interfaces instead.

    0 讨论(0)
提交回复
热议问题