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
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:
java.lang.Object java.util.AbstractCollection java.util.AbstractList java.util.Vector coldfusion.runtime.Array
The class hierarchy for an Adobe ColdFusion structure:
java.lang.Object coldfusion.util.CaseInsensitiveMap coldfusion.util.FastHashtable coldfusion.runtime.Struct
The Java class hierarchy behind a Railo array:
The Java class hierarchy behind a Railo structure:
The Java class hierarchy behind a BlueDragon array:
java.lang.Object com.naryx.tagfusion.cfm.engine.cfData com.naryx.tagfusion.cfm.engine.cfJavaObjectData com.naryx.tagfusion.cfm.engine.cfArrayData com.naryx.tagfusion.cfm.engine.cfArrayListData
The Java class hierarchy behind a BlueDragon structure:
java.lang.Object com.naryx.tagfusion.cfm.engine.cfData com.naryx.tagfusion.cfm.engine.cfJavaObjectData com.naryx.tagfusion.cfm.engine.cfStructData
Adendum: Ben Nadel has a good little post on ColdFusion Data Types from Different Sources and How ColdFusion Sees Them.