3 ms·
But then that interface needs to specify the behavior. And -- crucially -- ONLY that behavior. It's not possible in Go to say "this thing is unknown, but it wil
by malcolmgreaves 10y ago
But then that interface needs to specify the behavior. And -- crucially -- ONLY that behavior. It's not possible in Go to say "this thing is unknown, but it will have a specific behavior (type) at compile time." interface{} says it is known type that has no behavior.
- chewxy 10y agoIs that not the definition of what a interface is? If you want something that prints you define a printer interface that has exactly one method. Go highly encourages small interfaces
- grey-area 10y agoIn go: An interface says this thing is unknown but it has at least these known methods The empty interface means this thing is unknown and its methods are unknown The first is preferable and the second is not often used.
- bsaul 10y agoThe problem is we need the distinction between "author of the code" unknown ( in which case whatever symbol such as T is enough), and "user of the code" unknown ( in which case relying on dynamic casting or interfaces is fine). What go doesn't provide is 1/ unknown but 2/ not. Which happens when you're creating a lib to be used later.