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”.


a = true;
b = CreateObject("java","java.lang.Boolean").init("true");
c = "true";



	a = true;
b = CreateObject("java","java.lang.Boolean").init("true");
c = "true";



b.equals(a) #b.equals(a)#
a.equals(b) #a.equals(b)#
b.equals(JavaCast("boolean",a)) #b.equals(JavaCast("boolean",a))#
b is a #b is a#
a is b #a is b#

a.equals(c) #a.equals(c)#
c.equals(a) #c.equals(a)#
a is c #a is c#
c is a #c is a#

b.equals(c) #b.equals(c)#
c.equals(b) #c.equals(b)#
b is c #b is c#
c is b #c is b#

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

3 thoughts on “ColdFusion true is not a Java boolean

  1. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *