```go
package main
import (
"fmt"
)
type jiekou interface {
fangfa()string
}
type leixing struct {
a string
}
func (e *leixing) fangfa() string {
e.a="222"
return e.a
}
func run() jiekou {
return &leixing{
"111",
}
}
func main() {
fmt.Println(run())
}
```
请问输出结果为什么不是
222
而是
111
**********************************************
我是模仿下面这个程序写的,
```go
package main
import (
"fmt"
"time"
)
type MyError struct {
When time.Time
What string
}
func (e *MyError) Error() string {
return fmt.Sprintf("at %v, %s",
e.When, e.What)
}
func run() error {
return &MyError{
time.Now(),
"it didn't work",
}
}
func main() {
if err := run(); err != nil {
fmt.Println(err)
}
}
```
![image.png](https://static.studygolang.com/210608/b35a80ab10df2f7162d31e2dbb796e75.png)
#4
更多评论