It's a pattern that can be used to prevent external implementations of
the interface. Another example is the text/template package in the
standard library:
https://github.com/golang/go/blob/master/src/text/template/parse/node.go#L21

On Mon, 4 Sep 2017, at 01:21 PM, [email protected] wrote:
> hi,
> 
> in this code
> https://github.com/conformal/gotk3/blob/7a6ce3ecbc883d4d6a7aa1821bbc9633751fd67e/gtk/gtk.go#L7926>
>  
> a public interface with a private method is declared.
> 
> At first read, totally dubious. yeah?
> 
> A bit more testing, and i wonder in which case this is suitable, a
> basic example yields,> 
> ./main2.go:7: cannot use b.XX literal (type b.XX) as type a.WW in
> argument to a.C:  b.XX does not implement a.WW (missing a.private
> method)   have b.private()   want a.private()
>
> _$GOPATH/src/test/a/a.go_> 
> package a
>
> type WW interface { private() }
>
> func C(h WW) {}> 
> 
> _$GOPATH/src/test/b/b.go_
> 
> package b
> 
> type XX struct{}
> 
> func (x XX) private() {}
> 
> 
> _$GOPATH/src/test/main.go_
> 
> package main
>
> import "test/a" import "test/b"
>
> func main() {
>  a.C(b.XX{}) }> 
> 
> 


> --
>  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 [email protected].>  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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to