0

Or what is the interface that all types implement? I'm looking for something like the Object class in Java.

Is it possible for me to make my own kind of "Root" interface?

benbot
  • 1,217
  • 1
  • 12
  • 28
  • I think that there is no such thing as `Object` from java in golang, and the main reason is that golang enforces composability and not inheritance, anyway in general is a bad idea to add things to the global environment... also you should expand your question with the problem that you're trying to solve... – kainlite Jun 22 '15 at 00:17
  • There wasn't a real problem. It was a curiosity question :) – benbot Jun 22 '15 at 01:26

1 Answers1

3

Any type that implements all the methods listed in the interface implements the interface.

The empty interface, interface{}, lists no methods. Therefore, all types implement it.

There is nothing "top level" about it however. Interfaces (although they can embed) do not have a hierarchical structure. The empty interface is simply a normal interface with no requirements.

Stephen Weinberg
  • 51,320
  • 14
  • 134
  • 113
  • That's what I was thinking in terms of making a "root" interface. I just wasn't sure how to put it. – benbot Jun 22 '15 at 05:04