What replaces CreateObject?

according to the docs, createObject is deprecated

but it doesn’t explain what has replaced it and googling it just leads to flame wars without actually leading to an answer about what the new approach is?

For CFC’s, new - as in:

bob = new model.bean.alice();

or objectNew() - as in:

bob = objectNew( model.bean.alice, [optional args to pass] );

For Java components, there’s javaNew()

For webservices, webserviceNew()

See: https://bitbucket.org/lucee/lucee/wiki/Lucee_5_Functions_Tags for further details

HTH

– Denny

For anyone who missed the conversation back in the day, when those docs say “deprecated”, they don’t mean it’s going away. Basically, any time there are two ways to do the same thing, Micha always likes to “deprecate” one so people know which one is the recommended approach.

ok, I’ve filed a bug

ObjectNew, JavaNew, WebserviceNew missing from getFunctionList()
https://luceeserver.atlassian.net/browse/LDEV-1782

I tried this some time ago after moving to v5 and all I got was:

No matching function [JavaNew] found

Still getting that error. Ditto ObjectNew.

I can’t actually see these functions implemented in the Lucee 5 source, but perhaps I’m missing something.

It appears you are correct, sir. objectNew and javaNew do not appear to be implemented. Quite odd.

There was a ticket somewhere about allowing to create a Java object with

new java:package.Class();

e.g:

sb = new java:StringBuilder();    // java.lang package imported implicitly

queue = java.util.concurrent.PriorityBlockingQueue();

IMO that is much cleaner than a “javaNew()” function.

I think that along those lines, calling a static Java method should be implemented as

java:package.Class::someMethod();

e.g.

    // call static method java.lang.System.out.println()
java:System.out::println("Hello Lucee");

// call static method sort()
java:java.util.Collections::sort(myArray);

// call static method forName() on java.lang.Class
driver = java:java.lang.Class::forName("org.postgresql.Driver");

// or with the implicit package of java.lang:
driver = java:Class::forName("org.postgresql.Driver");

(I was hoping that the comments would be grayed out in the display)