On Sat, Dec 10, 2016 at 9:00 AM, T L <tapir....@gmail.com> wrote: > > > On Saturday, December 10, 2016 at 3:42:34 PM UTC+8, Axel Wagner wrote: >> >> I don't understand. You are saying, that you want a method on a pointer >> to Age and then find it unreasonable, that you are getting a method on a >> pointer to Age? >> >> If you don't want the argument to be a pointer, use Age.CanDrink instead. >> Both are valid, because the method set of *Age contains all methods >> declared on *Age or on Age (according to the spec >> <https://golang.org/ref/spec#Method_sets>). >> > > That is what it is weird, Age.CanDrink and (*Age).CanDrink should be the > same function. >
Why? Age and *Age are different types. Why would they be interchangeable in this case? When the programmer *explicitly* asked for different things? That seems like confusing (and infuriating) behavior to me. You need to come up with a reason why this should be the case, you can't simply state that it should. I'm sorry, you often make controversial but somewhat valid arguments about inconsistencies in go on this list, but this just isn't one of them. This is just an unreasonable complaint. > > >> >> On Sat, Dec 10, 2016 at 8:17 AM, T L <tapi...@gmail.com> wrote: >> >>> >>> package main >>> >>> import "fmt" >>> import "reflect" >>> >>> type Age int >>> func (age Age) CanDrink() bool { >>> age++ >>> return age >= 18 >>> } >>> >>> func main() { >>> var age Age = 11 >>> >>> Age.CanDrink(age) >>> // (*Age).CanDrink(age) // cannot use age (type Age) as type *Age in >>> argument to (*Age).CanDrink >>> (*Age).CanDrink(&age) >>> fmt.Println(age) // 11 >>> >>> fmt.Println(reflect.TypeOf(Age.CanDrink)) // func(main.Age) bool >>> fmt.Println(reflect.TypeOf((*Age).CanDrink)) // func(*main.Age) bool >>> } >>> >>> Why is the parameter of (*Age).CanDrink is a pointer? It is not >>> reasonable. >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "golang-nuts" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to golang-nuts...@googlegroups.com. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.