doulu8341 2016-12-14 16:11
浏览 88

相当于Python的NotImplementedException的Golang

Is there an equivalent in Golang to raising a NotImplementedException in Python when you define an interface with methods that you don't want to implement yet? Is this idiomatic Golang?

For example:

type MyInterface interface {
    Method1() bool
    Method2() bool
}


// Implement this interface
type Thing struct {}
func (t *Thing) Method1() bool {
    return true
}

func (t *Thing) Method2() bool {
    // I don't want to implement this yet
}
  • 写回答

2条回答 默认 最新

  • doutuoji8418 2016-12-14 16:16
    关注

    Usually in golang if you want to implement error handling you return an error

    type MyInterface interface {
        Method1() bool
        Method2() (bool, error)
    }
    

    Then you can return an error. You can also log, or panic as @coredump said in the comments.

    评论

报告相同问题?

悬赏问题

  • ¥15 蓝桥oj3931,请问我错在哪里
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染