go 1.19
代码如下:请问我错哪里了?
type ICanByteable interface {
ToBytes() ([]byte, error)
}
type XWJRequest[T ICanByteable] struct {
CmdCode uint16
Group uint16
RequestData T
}
func (r *XWJRequest[ICanByteable]) Test() {
fmt.Println(r.RequestData == nil)
}
type RequestData struct {
}
func (r *RequestData) ToBytes() ([]byte, error) {
return []byte{1, 2, 3}, nil
}
func main() {
var requestData *RequestData
request := &XWJRequest[ICanByteable]{
CmdCode: 0,
Group: 0,
RequestData: requestData,
}
request.Test()
}
使用go build
命令构建,提示运行报错:
.\main.go:16:31: invalid operation: r.RequestData == nil (mismatched types ICanByteable and untyped nil)