FAQ
// t satisfies the T interface
type t int; func (*t) Foo() { }

I don't think you can make this any smaller. You can only declare
methods on types that you own (ie, declare in the package).


On Sun, Jun 30, 2013 at 11:28 AM, wrote:
Hi all,
Is it possible to have an anonymous interface implementation (something
similar to anonymous structs)? In the code below I'd like to have a foo
implementation without declaring a struct.

-------------------------------------------------------------------
package main

type T interface {
Foo()
}

func Bar(t T) {
t.Foo()
}

func main() {
Bar(nil) //need quick foo implementation here without declaring a type and
declaring a method on it
}
--------------------------------------------------------------------

Thanks!

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 2 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJun 30, '13 at 1:28a
activeJun 30, '13 at 1:33a
posts2
users2
websitegolang.org

2 users in discussion

Dave Cheney: 1 post Shkarupin: 1 post

People

Translate

site design / logo © 2022 Grokbase