The Java Behind a ColdFusion Array and Structure

by Simon. Average Reading Time: almost 2 minutes.

Following a conversation with a friend regarding how ColdFusion handles arrays and structures in ‘the background’, I was interested to find out what Java classes each were mapped to. This was a relatively simple case of using the functions getClass(), getSuperClass() and getName() to parse out the name of the Java classes.

<!--- Arrays (repeat up the hierarchy) --->
<cfdump var="#arrayNew(1).getClass().getName()#">
<cfdump var="#arrayNew(1).getClass().getSuperClass().getName()#">
<!--- Structures (repeat up the hierarchy) --->
<cfdump var="#structNew().getClass().getName()#">
<cfdump var="#structNew().getClass().getSuperClass().getName()#">

What became immediately apparent was that both were handled differently. In the case of a ColdFusion array, the parent class was the java.util.Vector, which seemed obvious. The Vector class implements a growable array of objects. Like an array, it contains components that can be accessed using an integer index. However, the size of a Vector can grow or shrink as needed to accommodate adding and removing items after the Vector has been created.

ColdFusion structures, however, are handled entirely differently, with the parent class being a coldfusion.runtime class. In fact, as we can see below, the code to handle a ColdFusion structure is entirely written for ColdFusion until the root class of java.lang.Object. Clearly ColdFusion does some complex wizardry to handle the complex nature of structues (associative arrays).

The class hierarchy for an Adobe ColdFusion array:


The class hierarchy for an Adobe ColdFusion structure:


Being an inquisitive person, I applied the same code to Railo and BlueDragon, with equally interesting results.

The Java class hierarchy behind a Railo array:


The Java class hierarchy behind a Railo structure:


The Java class hierarchy behind a BlueDragon array:


The Java class hierarchy behind a BlueDragon structure:


Adendum: Ben Nadel has a good little post on ColdFusion Data Types from Different Sources and How ColdFusion Sees Them.

This article has been tagged

, , , , , , , , , , ,

Other articles I recommend

Railo – The CFML Engine

Railo is a ColdFusion Compiler for translating and executing of ColdFusion based websites.

ColdFusion (CFML) Engines

CFML is the name of the scripting language used by ColdFusion and several alternative server environments. It stands for ColdFusion Markup Language and is similar to HTML in appearance in that it uses tags. CFML is the code that powers ColdFusion, a program available from Adobe (formerly Macromedia), as well as such engines as BlueDragon, IgniteFusion, Railo, Coral Web Builder, and other web development platforms.

The Inner Workings of a ColdFusion Array and Structure

Array and Structures are considered to be complex data types in ColdFusion. In contrast, simple data types are ones that contain a single piece of data, such as an Integer, String, or Boolean value. A complex data type can contain multiple pieces of data, which, in the case of arrays, are usually related. All the data are referenced under a single variable name. You can think of a complex variable as a variable that contains a collection of other variables inside it. An array maps Integers to arbitrarily typed objects (Integers, Strings, Booleans and Objects) while a structure, or associative array, maps arbitrarily typed objects to arbitrarily typed objects.

  • Larry C.Lyons

    Hi Simon,

    Just thought you’d like to know I ran your code on Open Blue Dragon and got the same results as you with the commercial version of BD.


  • Larry Buta

    Hey Simon…great post…I’ve been needing to do some coding where taking advantage of java string methods became really useful (this is for a site that is still on an mx box) and knowing how to map the coldfusion object to its java class is gold…thanks…