Junior — Middle
Millist liidest implementeerib Map-struktuur Go keeles?
sobes.tech AI
Vastus AI-lt
In the Go language, the Map structure does not implement an interface in the classical sense, because map is an embedded data type for storing key-value pairs.
However, if we talk about interfaces, the map satisfies an interface for operations similar to map: access by key, 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 the map implements, it can be said that the map does not implement any standard interface, because in Go interfaces are defined by methods, and the map is a data type without methods.
To work with maps, you usually define your own interfaces if you need to abstract access to data.