关于接口的小问题

goCurrent · · 847 次点击
虽然不全懂,但是大概知道了,go语言的swicth是匹配到一个之后就停止了,这里先匹配到error就先用了error,十分感谢
#2
更多评论
fmt调用的源码是这样的 ``` switch verb { case 'v', 's', 'x', 'X', 'q': // Is it an error or Stringer? // The duplication in the bodies is necessary: // setting handled and deferring catchPanic // must happen before calling the method. switch v := p.arg.(type) { case error: handled = true defer p.catchPanic(p.arg, verb) p.fmtString(v.Error(), verb) return case Stringer: handled = true defer p.catchPanic(p.arg, verb) p.fmtString(v.String(), verb) return } } ```
#1