type Foo interface {}
func (f Foo) DoSomething(){}
func DoSomething(f Foo){}
On Tue, 18 Oct 2016 11:11:59 -0700 (PDT)
parais...@gmail.com wrote:
> Obviously in Go this is a compile time error :
>
> type Foo interface {}
>
>
> func (f Foo) DoSomething(){}
>
> I wonder if there is some technical limitations that make it
> undesirable or hard to implement, or it's just that Go designers
> didn't think it is a relevant feature.
>
> I personally think there is it could be handy in some situations,
> instead of having to write a function without receiver, it could
> allow to attach behavior to interfaces automatically
> instead of the explicit :
>
> func DoSomething(f Foo){}
>
>
> what is your opinion on the matter ? Unfortunately I wasn't able to
> catch anyone of the Go team during the recent conference in Paris to
> ask that question.
type Foo interface {
func DoSomething()
}
func (f Foo) DoSomething() {
}
var f Foo
f.DoSomething()
How do you propose to distinguish these two DoSomething()-s?
-j
--
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.
---j
-j
---j
type Foo interface {
Do()
}
func (f Foo)interface Do(){}
func AcceptFoo(f Foo){
f.Do() // Execute Foo.Do
}
type Bar struct {}
func(b Bar)Do()
bar := Bar{}
bar.Do() // execute Bar.Do()
// however
var bar2 Foo = Bar{}
bar2.Do() // execute Foo.Do()