I don't know about anyone else, but wanting to create little ad hoc Java classes in my CF apps in a common occurrence for me. With my CF Groovy project, it's both possible and very easy. No Java, no compiling, no classloading hacks.
Here's a simple example. I'm going to create an array of structs and then sort the array based on a specific field value (the 'date' field) of the structs. Doing this in CF usually means making a lookup struct, sorting that, and then rebuilding the array (but only if you have unique values), or converting to a query and using QofQ to do it. Both have serious drawbacks, as well as being very circuitous/obscuring.
First the array construction (six items, each with 'letter' and 'date' fields, holding what you'd expect). Nothing very interesting here.
<cfscript>
a = [];
month = createDate(year(now()), month(now()), 1);
for (i = 1; i LTE 6; i = i + 1) {
s = {
letter = chr(65 + randRange(0, 25)),
date = dateAdd("d", randRange(0, 30), month)
};
arrayAppend(a, s);
}
</cfscript>
Now, using the <g:script> tag from CF Groovy, we'll sort it by date using a java.util.Comparator:
<g:script>
Collections.sort(variables.a, {o1, o2 ->
o1.date.compareTo(o2.date)
} as Comparator)
</g:script>
If you want to compare based on the letter, just change the two ".date" references to ".letter". You can, of course, make the comparator as complicated as you'd like, including referencing other Groovy classes through CF Groovy's classloading, or other Java classes on your classpath.
You can see it in action at the demo page, or get the full source from Subversion at https://ssl.barneyb.com/svn/barneyb/cfgroovy/trunk/demo/.