I was talking with Luis the other day about some ColdFusion and framework specific stuff that we would like to see in the upcoming ColdFusion 9. During the conversation Luis pointed something out to me that I hadnt known before. After using ColdFusion for over 10 years, Im almost ashamed to admit that I didnt know this. But then again, I didnt have any OO programming knowledge and other than classic ASP I had no programming experience at all when I started working with ColdFusion.
Strings in ColdFusion are not just Strings. They are actually Java strings. Duh you say? I guess I got so used to CF not being typed that I never really thought about it. So for those as clueless as I am, heres what that means.Anytime you create a simple string variable in ColdFusion, it inherits methods from the Java String Class. Lets look at an example:
That code would obviously output the variable “test” in all uppercase. Since ColdFusion automatically types the variable for us, we can take advantage of the inherited Java methods in our ColdFusion code. Heres another example:
Strings are not the only thing that ColdFusion types for us automatically. Integers are handled as well. The following snippet would return a boolean of false:
And the last example would return a value of -5:
Im not really sure how useful any of this is, but it is quite cool to play with! The simplicity of ColdFusion can make you forget that there really is an Object Oriented language called Java lurking beneath the covers.