July 12, 2018
Enhanced Support For New Operator
Comments
(4)
July 12, 2018
Enhanced Support For New Operator
Newbie 4 posts
Followers: 7 people
(4)

In the 2018 release of ColdFusion, there is a handy way to create objects in ColdFusion.

The snippet below illustrates how you can use the new operator to create different type of objects.

 

//ColdFusion Component

obj = new component(“path.to.cfc”)

obj.init()

 

// Java

obj = new java(“java.class”)

obj.init()

 

// WebService

obj = new webservice(“http://webservice?wsdl”, {“webservice”: “parameters”})

 

Similarly, you can use the new operator to create com, CORBA, and .NET objects as well.

4 Comments
2022-03-27 10:22:26
2022-03-27 10:22:26

Where is the new java() function documented? I can see that passing _multiple arguments_ is doing _something_. However, I cannot find the documentation to see what it is. For example, if I do this:

“`
new java( “org.jsoup.Jsoup”, “jsoup-1.14.3.jar” );
“`

I get the error:

“Jar not found in repository : /jsoup-1.14.3.jar:null”

… so clearly, the java() constructor takes more than one argument (since why else would the 2nd arg show up in the error message). But, I don’t know what signature it is looking for. Can you please point me to the documentation? Google is failing me.

Like
2018-08-16 09:44:36
2018-08-16 09:44:36

Hi Adobe,

+1 to an answer to Brad’s question. What happened to the discussed/preferred syntaxes that no longer work?

Thanks!,
-Aaron

Like
(1)
2018-07-12 19:56:19
2018-07-12 19:56:19

Just to be clear, this syntax calls init for you:
obj = new path.to.cfc();

but this one doesn’t:
obj = new component(“path.to.cfc”);

What happened to the other syntax I saw during the prerelease– did this go away?

new java:java.lang.String();

Like
(1)
>
bradwood.com
's comment
2019-02-17 18:35:46
2019-02-17 18:35:46
>
bradwood.com
's comment

I know this is an old post, but it does appear that new component(“path.to.cfc”) does call init(). Am I missing something or just reading old information?

Like
Add Comment