Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Invalid type assertion by pointer to array

I’m new to golang and confused about the type assertion. Why can’t the following snippet be compiled? what could be the problem by the type assertion in this example?

arr := new([5]int)
arr1, ok := arr.(*[5]int)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

type assertion is only for interface.

A type assertion provides access to an interface value’s underlying concrete value.

source https://go.dev/tour/methods/15

example:

    arr := new([5]int)
    i := interface{}(arr)
    arr1, ok := i.(*[5]int)
    fmt.Println(arr1, ok)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading