为了账号安全,请及时绑定邮箱和手机立即绑定

MessageImpl 没有实现 Message

MessageImpl 没有实现 Message

Go
MMMHUHU 2021-10-25 16:51:02
在 golang 中,我遇到以下编译错误:cannot use m (type MessageImpl) as type Message in assignment:    MessageImpl does not implement Message (missing FirstLine method)使用以下代码:type Message interface {  FirstLine() string  /* some other method declarations*/}type MessageImpl struct {  headers     []Header  /* some other fields */}type Request struct {  MessageImpl  /* some other fields */}type Response struct {  MessageImpl  /* some other fields */}func (r Request) FirstLine() string {  var requestLine bytes.Buffer  requestLine.WriteString("...")  // Some more instructions  return requestLine.String()}func (m MessageImpl) RenderMessage() string {  var message bytes.Buffer  var msg Message = m                   // <=== This is the line the compiler moans about  message.WriteString(msg.FirstLine())  // Some more instructions  return message.String()}来自java语言,我将尝试表达我的意图:让一些接口Message定义一些由抽象类实现的方法MessageImpl。两个真正的类Request,Response应该继承MessageImpl(并实现接口Message)。这两者都定义并实现了一些更多的内部方法。这是如何做到最好的?
查看完整描述

添加回答

代码语言

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号