On Mon, Aug 18, 2025 at 9:25 AM 'andreas graeper' via golang-nuts
<golang-nuts@googlegroups.com> wrote:
>
> type I interface { m()bool }
> type T struct { x bool }
>  func (o T) m()bool { return o.x }    // o:object
>  func (p *T) m()bool { return p.x }   // p:pointer
>
> both does not work. it is not possible to implement I for T and *T ( m 
> already defined )
>
> func fi(i I){}
> func fp(i*I){}
>
> fi(o) if  T implements I
> fi(p) if *T implements I
>
> fp(p) or fp(&o) does not work at all, cause i dont know, how to implement *I
> looks little strange to me.

If T has a method m, then *T has the same method (see
https://go.dev/ref/spec#Method_sets). So given

func (o T) m()bool { return o.x }    // o:object

then both type T and  type *T implement I.

If that doesn't help, what are you really trying to do?

Ian

-- 
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.
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXdUG7T-aB8yPzaWQeRti71n3nfCT5L_q0Q1v_dk_PgCQ%40mail.gmail.com.

Reply via email to