package main import ( "fmt" "reflect" ) func main() { slice := make([]int, 0) elemType := reflect.TypeOf(slice).Elem() fmt.Println(elemType) }
package main import ( "fmt" "go/types" ) func main() { var array = [5]string{"a", "b", "c", "d", "e"} elementType := types.NewArray(types.Typ[types.String], 5).Elem() fmt.Println(elementType) }In this example, we create an array of strings and get the element type of the array using the "Elem" method of the "go/types" package. We then print the type of the element, which is "string". Package library: "go/types"