I am learning golang from "gotour" tool with "go1.10 darwin/amd64".
For below case:
package main
import "fmt"
type Myapi interface {
fun1() int
}
type MyintA struct {
val int
}
type MyintB int
func (v *MyintA)fun1() int {
return int(v.val) + 1
}
func (v *MyintB)fun1() int {
return int(*v) + 1
}
func main() {
var a Myapi
a = &MyintA{3}
fmt.Println(a)
a = &MyintB(2) // Need b:=MyintB(2); a=&b
fmt.Println(a)
}
The compiling error is:
$ go run try.go
# command-line-arguments
./try.go:27:9: cannot take the address of MyintB(2)
Why the interface variable could get address directly from MyintA but not MyintB in this case?