Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

// request.cf · coarse context

A page that knows where it met you.

Only coarse request metadata is shown. This demo does not display or persist visitor IP addresses.

Country
US
Cloudflare location
CMH
Connection
HTTP/2
Language
Not provided

Ray ID: a2624b776e6baedd

Jump to content

Draft:Heterogeneous Collections

From Wikipedia, the free encyclopedia


'''Heterogeneous collection''' is a term in computer science for a data structure or container that can hold elements of more than one data type.

== Definition ==

A heterogeneous collection is a container that holds elements of different types. This contrasts with a homogeneous collection, which holds only one type (for example, List<int> or an array of doubles).

Introductory teaching material from Tufts University uses struct as an example of an aggregate type that can combine fields of different types, describing such aggregates as a way to represent heterogeneous data. Tufts University ECE and CS Departments, “Comp 11: Heterogeneous Aggregate Storage”.

In Java, a collection declared with element type Object can store values of different runtime types (for example, String, numeric wrapper types, and custom classes), although this approach typically relies on runtime type checks and casts. See javaspring.net, “What is a Heterogeneous Object in Java? Understanding Collections with Object Class and Mixed Types”.

== Use cases ==

Heterogeneous collections are used when a program needs to represent or exchange values that do not share a single uniform type, including:

* Representing a single conceptual entity with multiple attributes of different types (for example, a struct with string, integer, and boolean fields).

* Supporting extensible systems that must accept values of many possible types (for example, serialization, dependency injection, or messaging systems).

* Modeling dynamically typed data formats (for example, JSON values that may be strings, numbers, arrays, or objects).

== Examples ==

* Records and structs: Aggregate types can combine fields of multiple types in a single value.

* Universal-base-type containers: Some statically typed languages allow collections whose element type is a top type such as Object (Java), enabling storage of different runtime types in one collection.

* JSON DOM models: Libraries may represent any JSON value using a single node type (for example, a tagged union).

* Dynamically typed languages: In languages such as Python and JavaScript, list/array types can commonly store mixed element types.

== Trade-offs ==

Heterogeneous collections can improve flexibility, but they are often associated with reduced static type guarantees and additional runtime checking in statically typed languages.

== Potential advantages ==

* Flexibility for loosely structured data

* Convenience for infrastructure code that must accept arbitrary payloads ;Potential disadvantages * Reduced compile-time type safety (elements may require casts)

* Increased likelihood of runtime type errors (for example, ClassCastException)

* Possible performance overhead from type checks, boxing, or dynamic dispatch

== See also ==

* Record (computer science)

* Tagged union

* Type system

* Polymorphism (computer science)

* Generics in Java

== External links == *http://www.eecs.tufts.edu/~msheldon/cs15_2021s_summary/reference/comp11_structs/index.shtml

* https://www.javaspring.net/blog/what-is-an-heterogeneous-object-in-java/