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.
 

>
> On Sat, Dec 10, 2016 at 8:17 AM, T L <tapi...@gmail.com <javascript:>> 
> 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 <javascript:>.
>> 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.

Reply via email to