Junior — Middle
What interface does the Map structure implement in Go?
sobes.tech AI
Answer from AI
In the Go language, the Map structure does not implement an interface in the traditional sense, as map is a built-in data type for storing key-value pairs.
However, when talking about interfaces, a map satisfies an interface of map-like operations: key access, addition, deletion, and key existence check.
Example of using a map in Go:
package main
import "fmt"
func main() {
m := make(map[string]int)
m["apple"] = 5
fmt.Println(m["apple"]) // output: 5
}
If the question is about which interface a map implements, it can be said that a map does not implement any standard interface, as interfaces in Go are defined by methods, and a map is a data type without methods.
To work with maps, custom interfaces are usually defined if data access needs to be abstracted.