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.
--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.