02

September 1, 2024 · 2 min read

Can One Array Hold Mixed Data Types?

A short, careful answer to a question that hides a real design decision: what a collection type is actually for.

[ADD — paste the original article text here, or write it fresh. The published post posed the question directly: can a single array store string, int, float and char values together?]

The short answer

[ADD — the language-level answer, stated precisely, with the exception cases.]

The better question

[ADD — the design argument: heterogeneous collections are usually a signal that a type is missing, and that modelling the missing type is cheaper than maintaining an array that lies about its contents.]

Originally published

LinkedIn — 2024