如何让变量的类型为变量类型?在Go中为变量指定类型
这是什么意思?我有一个python和java背景。在这两种语言中,我都可以执行诸如将类名分配给变量的操作。
#Python
class A:
def __init__(self):
self.a = "Some Value"
# And asigning the class name to a variable
class_A = A
# And create instance from class A by using class_A
a = class_A()
有没有这样的机制让我这样做呢?在他们的文档中,我无法知道该在哪里寻找这些东西。老实说,通常我不知道这些在编程语言中被称为什么。
比如我想能够做到:
// For example, what would be the type of myType?
var myType type = int
我将利用这一机制,采取“类型”参数。例如:
func Infer(value interface{}, type gotype) {...}