Welcome To Golang By Example

Menu
  • Home
  • Blog
  • Contact Us
  • Support this website
Menu

Constant Map in Go (Golang)

Posted on September 30, 2020September 30, 2020 by admin

Table of Contents

  • Overview
  • Example

Overview

Go only supports four types of constant

  • Numeric ( int, int64, float, float64, complex128 etc)
  • String
  • Character or rune
  • Boolean

Go doesn’t support const map. So below program would raise a compilation error

Example

package main

func main() {
	const e = map[string]int{
		"a": 1,
	}
}

Output

const initializer map[string]int literal is not a constant
  • go
  • golang
  • Follow @golangbyexample

    Popular Articles

    Golang Comprehensive Tutorial Series

    All Design Patterns in Go (Golang)

    Slice in golang

    Variables in Go (Golang) – Complete Guide

    OOP: Inheritance in GOLANG complete guide

    Using Context Package in GO (Golang) – Complete Guide

    All data types in Golang with examples

    Understanding time and date in Go (Golang) – Complete Guide

    ©2025 Welcome To Golang By Example | Design: Newspaperly WordPress Theme