About the type of key for map in Golang

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Golang in the map, the key can be many types, such as bool, number, string, pointer, channel, and only contains the previous types of interface types, structs, arrays

Obviously, slice, map and function are not allowed, because these can not use = = to judge

The original text reads as follows:

As mentioned earlier, map keys is comparable. The language spec defines this precisely, but in short, comparable types is Boolean, numeric, string, pointer, channel, a nd interface types, and structs or arrays that contain only those types. Notably absent from the list is slices, maps, and functions; These types cannot is compared using == , and May is not used as map keys.


The two structs are exactly equal, meaning that the values of all the variables inside are exactly equal, and the examples in the original text are as follows:

Type Key struct {      Path, country string}hits: = Make (Map[key]int)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.