The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
thomaswang

golang struct

  •  
  •   thomaswang · Sep 21, 2018 · 3029 views
    This topic created in 2815 days ago, the information mentioned may be changed or developed.

    一个 struct 实现接口中的方法,是必须写在 struct 当前文件里面,还是必须写在 struct 当前文件所在的 package 里面,还是可以随意位置

    在其他文件这个 struct 对象调用方法,我用的 goland,点击这个方法总是跳到 interface,不好找这个方法的实现

    我说的不清楚,大家明白我的意思吗

    4 replies    2018-09-21 12:25:24 +08:00
    markx
        1
    markx  
       Sep 21, 2018
    应该写在 package 里面就可以,可以在不同的文件里。
    LuoyeBug
        2
    LuoyeBug  
       Sep 21, 2018
    一个包里面就行,不限制文件。
    zhs227
        3
    zhs227  
       Sep 21, 2018
    package 里面,可以任意位置。goland 跳到接口是因为当前推断就是 interface。比如函数参数的传入类型是 interface。
    lbp0200
        4
    lbp0200  
       Sep 21, 2018
    package main

    type animal interface {
    fuck()
    }

    type human struct {
    age int
    }

    func (h human) fuck() {
    println("oh my yes")
    }

    func main() {
    var p animal
    p = human{age: 18}
    p.fuck()
    }
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1011 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 23:27 · PVG 07:27 · LAX 16:27 · JFK 19:27
    ♥ Do have faith in what you're doing.