invalid receiver type

Because in a case like this:

type I int
type P *I
func (i I) Get() int { return int(i) }
func (p P) Get() int { return int(*p) }
var v I
var x = (&v).Get()

it would be unclear whether the Get method in the last line would be
I.Get or P.Get.  We could define a rule for it, but that would become
another thing that people would have to know.

 

https://groups.google.com/forum/#!topic/golang-nuts/qf76N-uDcHA

posted @ 2016-08-07 10:38  jvava  阅读(608)  评论(0编辑  收藏  举报