Why does Go's map iteration order vary when printing?

前端 未结 4 878
遥遥无期
遥遥无期 2020-12-18 12:48
package main

import \"fmt\"

func main(){
    sample := map[string]string{
    \"key1\":\"value1\",
    \"key2\":\"value2\",
    \"key3\":\"value3\",
    }
    for          


        
4条回答
  •  粉色の甜心
    2020-12-18 13:37

    Yes, it varies and even intentionally (iteration of a non modified map has been stable before). The intent is to catch as early as possible the situation when someone wrongly assumes a stable iteration guarantee. Additionally, with the added freedom for map implementation there comes more possible future optimizations of that part of the run time library.

提交回复
热议问题