Standard library / reflect

reflect.ArrayOf()

Construct an array type of the specified length and element type. An invalid length or excessive size panics. Expected stdout: '[3]int\n'.

Formal Syntax & Structure

go syntaxgo
func ArrayOf(length int, elem Type) Type

Parameters & Attributes

NameTypeDescription
lengthintArray length; must be nonnegative and representable.
elemTypeElement type of the new composite type.

Return Value

Type

Construct an array type of the specified length and element type.

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect")
func main() { fmt.Println(reflect.ArrayOf(3, reflect.TypeOf(0))) }
Go Reference