4

While declaring an array or a slice I'm required to specify the type of data that I want to store in the array or list.

How do I make an array that can hold data of multiple types ?

1 Answer 1

8

You can do something like this mixedArray := []interface{}{"astring", 10, &Object{'hello'}}

Most likely the values that you want to hold share some behavior, in that case what you should really do is create an interface and simply make the array content type that interface.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.