implement方法, 结构体快速自动生成结构体方法代码, Alt+Shift+Enter, var _ someInterface =(*someStruct)(nil)

1 goland windows 点击Alt+Shift+Enter var _ someInterface =(*someStruct)(nil)

package main
type someInterface interface {
	DoSomething()
	DoAnotherThing()
}
type someStruct struct {}
//如何快速实现接口- how to quick implsomeInterface for someStruct,
//go语言没有implement关键字
// 1. imple someInterface for someStruct
// 2.
var _ someInterface =(*someStruct)(nil)

2 点击 截图中的implement或者Alt+Shift+Enter之后,自动生成结构体的方法,生成之后代码如下: var _ someInterface =(*someStruct)(nil)

package main
type someInterface interface {
	DoSomething()
	DoAnotherThing()
}
type someStruct struct {}

func (s someStruct) DoSomething() {
	panic("implement me")
}

func (s someStruct) DoAnotherThing() {
	panic("implement me")
}

//如何快速实现接口- how to quick implsomeInterface for someStruct,
//go语言没有implement关键字
// 1. imple someInterface for someStruct
// 2.
var _ someInterface =(*someStruct)(nil)
posted @ 2023-03-19 14:39  ty1539  阅读(42)  评论(0编辑  收藏  举报