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 array or slice. It is because in go constant value is computed at compile time. Arrays or slices are always evaluated at run time. So below program would raise a compilation error
Example
package main
func main() {
const e = [1]int{1}
}
Output
const initializer [1]int literal is not a constant