Adam Cameron
Eric: ... The general rule is no member functions.Can you clarify what you mean by that? #ItsATrap
elpete
02/24/2022, 2:09 PMarraySlice( javaArray, … )
but not javaArray.slice( … )
.
I was mentioning that the built-in functions like arraySlice
will convert the Java array when it's passed in, but the member functions do not. It makes sense when you think about why, but can be initially confusing.elpete
02/24/2022, 2:10 PMAdam Cameron
Adam Cameron
cfmlArray = ["a", "b", "c"]
javaArray = cfmlArray.toArray()
writeDump([
cfml = [
array = cfmlArray,
class = cfmlArray.getClass().getName(), // coldfusion.runtime.Array <-- they are completely different types of object
methods = arrayMap(cfmlArray.getClass().getMethods(), (method) => method.getName()) // therefore they have completely different methods
],
java = [
array = javaArray,
class = javaArray.getClass().getName(), // java.lang.Object[] <-- they are completely different types of object
methods = arrayMap(javaArray.getClass().getMethods(), (method) => method.getName()) // therefore they have completely different methods
]
])
When one says just "array" one is being imprecise. They are actually objects of two completely different types of class.
So... like... obviously (?) one can only call the methods for the class the object is a type of?
It's not about "you can't call member functions on a java array". It's "you can't call the member functions of a coldfusion.runtime.Array
on an object that isn't a coldfusion.runtime.Array
.
Now... the way CFML member functions are implemented are not quite as straight fwd as that because... ugh... CFML sux, basically... but for the purposes of this discussion that's how you need to understand it.Adam Cameron
me.adamcameron.util.Array
, and it's an array, but that doesn't mean you can call methods from coldfusion.runtime.Array
or java.lang.Object[]
. You can only call its own methods, ie the ones defined in the me.adamcameron.util.Array
class.elpete
02/24/2022, 7:53 PMarraySlice
and array.slice
seem like two different syntaxes for the same thing when in fact they are different.Adam Cameron
But coming from a pure CFML perspectiveI'm not sure this is a "Pure CFML perspective" situation. This is a pretty fundamental programming thing. But anyway... we got there. All good.