newoperator 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 casting
variable: The value to cast
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.cfcallows you to declare a
this.javaSettingsstruct 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.cfcstructure takes in 3 keys that will allow you to class load any jar/.class libraries into the running ColdFusion application:
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.