Starting a new thread on this as the current discu...
# cfml-general
a
Starting a new thread on this as the current discussion is buried way down an unrelated thread. @Daniel Mejia & @elpete this is extracted from a conversation you were having.
Eric: ... The general rule is no member functions.
Can you clarify what you mean by that? #ItsATrap
e
Daniel was asking why he could use certain functions on Java arrays and not others. Specifically, he could call
arraySlice( 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.
So that phrase specifically meant you can't use CFML member functions on Java arrays, but you usually can pass a Java array to a BIF that expects a CFML array.
👍🏾 1
a
Oh I see: that makes more sense. But it's a curious way of explaining it.
Maybe try this: https://trycf.com/gist/f61fa9bf51ccfad8e4e7888647629fdd/acf2021?theme=monokai
Copy code
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.
👍🏾 1
I could implement a class
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.
e
Like I said, it makes sense when you think about the fact that you have two different objects. But coming from a pure CFML perspective
arraySlice
and
array.slice
seem like two different syntaxes for the same thing when in fact they are different.
👍🏾 1
a
But coming from a pure CFML perspective
I'm not sure this is a "Pure CFML perspective" situation. This is a pretty fundamental programming thing. But anyway... we got there. All good.