dongtan8122 2018-12-03 09:21
浏览 12
已采纳

结构声明样式之间的句法/语义差异

Any difference between these two declarations?

type Foo = struct {
    F string `zoom:"1"`
}

and

type Foo struct {
    F string `zoom:"1"`
}

they both compile and seem to work the same.

  • 写回答

1条回答 默认 最新

  • dongnuan7956 2018-12-03 09:26
    关注

    The 2nd one, it's an example of struct declaration.

    type Foo struct {
        F string `zoom:"1"`
    }
    

    And the 1st one, it is usage example of go1.9 new feature: type aliases.

    A new type Foo is created. It's an alias of an anonymous struct.

    type Foo = struct {
        F string `zoom:"1"`
    }
    

    The type aliases syntax can be used to define a struct. In example above, it's generating an equivalent result like type Foo struct.

    But, the original purpose of type alias is to make an alias from defined type.

    In example below, a new type called Bar is created and it's an alias of Foo struct.

    type Foo struct {
        F string `zoom:"1"`
    }
    type Bar = Foo
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog