31

I've been playing around with Go a little bit making some data structure libraries and I have one big problem. I want the data structure to be able to contain any type, but I don't see any way to do this in Go because you can't declare void pointers and they don't have a class like NSObject that everything inherits from. How would I achieve this same functionality in Go?

evanmcdonnal
  • 46,131
  • 16
  • 104
  • 115

1 Answers1

39

According to the Go Programming Language Specification:

A type implements any interface comprising any subset of its methods and may therefore implement several distinct interfaces. For instance, all types implement the empty interface:

interface{}

If you search within that document for interface{}, you'll see quite a few examples of how you can use it to do what you want.

ruakh
  • 175,680
  • 26
  • 273
  • 307
  • Just wanted to thank you for your answer. I just modified my LinkedList to use a type which implements the blank interface. Pretty awesome how simple it is to achieve something like that with the interface and loose typing. – evanmcdonnal Jan 27 '12 at 00:59