A Tour of Go Map literals

Map literals are like struct literals, but the keys are required.

package main 

import "fmt"

type Vertex struct {
    Lat, Long float64
}

var m = map[string]Vertex {
    "Bell Labs": Vertex {
        40.6833, -74.39967,
    },
    "Google": Vertex{
        37.42202, -122.08408,
    },
}

func main() {
    fmt.Println(m)
}
时间: 2024-10-22 18:41:08

A Tour of Go Map literals的相关文章

A Tour of Go Map literals continued

If the top-level type is just a type name, you can omit it from the elements of the literal. package main import "fmt" type Vertex struct { Lat, Long float64 } var m = map[string]Vertex { "Bell Labs": {40.68433,-74.39967}, "Google

A Tour of Go Struct Literals

A struct literal denotes a newly allocated struct value by listing the values of its fields. You can list just a subset of fields by using the Name: syntax. (And the order of named fields is irrelevant.) The special prefix & constructs a pointer to a

go语言笔记——map map 默认是无序的,不管是按照 key 还是按照 value 默认都不排序

示例 8.1 make_maps.go package main import "fmt" func main() { var mapLit map[string]int //var mapCreated map[string]float32 var mapAssigned map[string]int mapLit = map[string]int{"one": 1, "two": 2} mapCreated := make(map[strin

译文:Java8 Map Enhancement

此篇为Jooq官方博客的一篇译文,特此声明. Java 8 的好处: Map Enhancements 此次增强的 大部分API实际上是 新的Streams API的一部分.但是一些新的特性同样加入到 java.util.List 之中 并且最重要的是对 java.util.Map 的增强. 为了保证向后兼容, 所有被加入到Interface中的方法皆为默认方法.因此我们在使用过程中会有一些意外的小惊喜. compute() methods 过去,我们常获取一个map集合的view,在view上

5.map

Declare, initialize and iterate // Sample program to show how to declare, initialize and iterate // over a map. Shows how iterating over a map is random. package main import "fmt" // user defines a user in the program. type user struct { name st

Go structs、slices、maps

[Go structs.slices.maps] 1.定义时*在变量名后面,使用时*在变量名前面. 2.定义struct,type在前,struct关键字在后. 3.指针可以指定struct. 4.A struct literal denotes a newly allocated struct value by listing the values of its fields. You can list just a subset of fields by using the Name: sy

来自 Thoughtram 的 Angular 2 系列资料

Angular 2 已经正式 Release 了,Thoughtram 已经发布了一系列的文档,对 Angular 2 的各个方面进行深入的阐释和说明. 我计划逐渐将这个系列翻译出来,以便对大家学习 Angular 2 提供一些方便. Getting Started Building a Zippy component in Angular 2 Developing a Tabs component in Angular 2 Angular 2 Template Syntax demystifi

[转]50 Shades of Go: Traps, Gotchas, and Common Mistakes for New Golang Devs

http://devs.cloudimmunity.com/gotchas-and-common-mistakes-in-go-golang/ 50 Shades of Go: Traps, Gotchas, and Common Mistakes for New Golang Devs Go is a simple and fun language, but, like any other language, it has a few gotchas... Many of those gotc

Gradle cookbook(转)

原文地址 http://www.gradle.org/docs/current/userguide/installation.html 4.1. Prerequisites先决条件 Gradle依赖于JDK,需要已经安装好5.0(包括)以上的版本.虽然Gradle是基于Groovy配置的,但是不需要安装Groovy,它自带了.如果你已经安装了Groovy,没有关系,它会忽略掉的. Gradle会在Path路径寻找JDK,找到哪个版本就用哪个版本.你自己可以用 java -version来检查你的