ColdFusion true is not a Java boolean
None of these ColdFusion constructs strictly equate to a true-valued Java boolean (or Boolean):
true "true" 1 YES
But this does:
JavaCast("java.lang.Boolean", true);
Makes me wonder what ColdFusion’s literal true (no quotes) actually is. Probably just a string.
Edit prompted by Todd:
Definitely just a string. And definitely not a boolean. Also not particularly suprising but something I’d never thought about is the fact that ColdFusion “is” is not the same as Java “equals”.
-
<cfscript>
-
a = true;
-
b = CreateObject("java","java.lang.Boolean").init("true");
-
c = "true";
-
</cfscript>
-
-
<cfoutput>
-
a = true;<br>
-
b = CreateObject("java","java.lang.Boolean").init("true");<br>
-
c = "true";<br>
-
<br>
-
<cfdump var="#a.getClass().getName()#"><br>
-
<br>
-
b.equals(a) #b.equals(a)#<br>
-
a.equals(b) #a.equals(b)#<br>
-
b.equals(JavaCast("boolean",a)) #b.equals(JavaCast("boolean",a))#<br>
-
b is a #b is a#<br>
-
a is b #a is b#<br>
-
<br>
-
a.equals(c) #a.equals(c)#<br>
-
c.equals(a) #c.equals(a)#<br>
-
a is c #a is c#<br>
-
c is a #c is a#<br>
-
<br>
-
b.equals(c) #b.equals(c)#<br>
-
c.equals(b) #c.equals(b)#<br>
-
b is c #b is c#<br>
-
c is b #c is b#<br>
-
</cfoutput>
gives this:
a = true;
b = CreateObject("java","java.lang.Boolean").init("true");
c = "true";
java.lang.String
b.equals(a) NO
a.equals(b) NO
b.equals(JavaCast("boolean",a)) YES
b is a YES
a is b YES
a.equals(c) YES
c.equals(a) YES
a is c YES
c is a YES
b.equals(c) NO
c.equals(b) NO
b is c YES
c is b YES
Try this:
Cfset a = true
cfdump a.getclass().getname()
Good idea. Post edited.
ColdFusion handles boolean evaluation in a similar fashion as JavaScript/ECMAScript does.
Probably the biggest difference is that JS will treat any string with a positive length as true and any empty string as false. This means the string “true” and “false” both evaluate as true ince the strings have a positive length.