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

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

时间:2023-03-19 14:44:42浏览次数:49  
标签:someStruct someInterface nil Shift var implement

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)

标签:someStruct,someInterface,nil,Shift,var,implement
From: https://www.cnblogs.com/heris/p/17233041.html

相关文章