createObject()
or the new
operator approach. Here is the signatures for both approaches:JavaCast()
function built-in to the language.javaCast()
method takes in two arguments:type
: The type of castingvariable
: The value to castboolean
double
float
int
long
string
null
byte
bigdecimal
char
short
[]
in the casting construct. Let's create a stream from an incoming list of values and cast them to an array of objects in Java.createObject( "java" )
method will look into the CFML engine's class loader to discover the class you request. If the class is not located an exception is thrown that the class could not be found. If you want to integrate with third-party Jar's and libraries then you will need to tell the engine where to look for those classes. There are essentially three ways to add custom libraries to the CFML engine:Application.cfc
allows you to declare a this.javaSettings
struct where you can declare an array of locations of the libraries to load upon application startup with some nice modifiers. This will allow you to store and even leverage CommandBox for the management of such jars.createObject( "java" )
construct allows you to pass in a third argument which can be a location or an array of locations of libraries to class load. This is also great for custom CFCs, task runners, or isolated class loading.Application.cfc
structure takes in 3 keys that will allow you to class load any jar/.class libraries into the running ColdFusion application:loadPaths
loadColdFusionClassPath
reloadOnChange
watchInterval
watchExtensions
.class and .jar
files are monitored.createobject()
with a class from those libraries, now ColdFusion will know about them and create them.createObject()
call to do class loading. Please note that only Lucee supports this feature as of now.