Native Array (java.lang.String[]) - no member function each()

I have an array returned from Java ( Native Array (java.lang.String[]) ) that I can use as an array in

<cfloop array="#shares#"  item="share">

but not as a member function


No matching Method/Function for [java.lang.String;.each(lucee.runtime.type.Closure) found

Should member functions be able to handle Java Arrays?


Think about what your code is doing: someObj.someMethod() is calling someMethod() on someObj. For that to work, the class that someObj is an instance of needs to have a someMethod() method implementation. In your specific case, java.lang.Array doesn’t have an each() method. How were you expecting what you’re suggesting to work? Are you expecting Lucee to somehow note the object you’re calling the method on doesn’t have the method you’re asking for, and go off and look for it somewhere else instead? What would the rules for that be? Or are you expecting Lucee to intervene with non-Lucee objects being created, and wrap them in Lucee objects somehow? How would the rules for that work?

I understand what you are saying, and if that is the answer I can live with that. As for the rules, what ever CFLOOP is doing.

this shows the rules ColdFusion uses

String => Array

So after a lot of Googling and hacking, I have it working using

cfmlArray = [];
ok = createObject("java", " java.util.Collections").addAll(cfmlArray, stringArray);

is there a better way of converting String ( or any object ) to a CFML array?

But that’s a different thing entirely. That’s not calling a method on an object, that’s converting an object of one type to that of another type.

No-one’s suggesting any difficulty converting from one type to another; it’s simply about calling a method on an object that doesn’t have that method. Not the same.

As for how to convert a Java array to a CFML one, just use yourCfmlArray = [].append(yourJavaArray, true). Only superficially tested, but seems to work.

1 Like

Thanks, working for me too