douzi115522 2017-07-25 06:10
浏览 11
已采纳

在Go中为变量分配类型

How to have a variable whose type is a variable type?

What do I mean by that? I have a python and java background. In both languages I can do things like assigning a class name to variable.

#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()

Is there such a mechanism in go that allows me to do that? I couldn't know where to look at for such things in their documentation. Honestly, generally I don't know what these are called in programming languages.

For example I would like to be able to do:

// For example, what would be the type of myType?
var myType type = int

I will use this mechanism to take "type" arguments. For example:

func Infer(value interface{}, type gotype) {...}
  • 写回答

3条回答 默认 最新

  • dongya8378 2017-07-25 06:54
    关注

    Is there such a mechanism in go that allows me to do that?

    No there is not.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源