java:call
(java:call object "methodName" args...)
Invokes an instance method on a java object by reflection, choosing the
overload whose parameters best match the arguments, and returns the marshalled
result (a void method returns nil). Part of the JVM-only java interop
package — available on the interpreter and in JVM-compiled classes, not on the
WASM backend. See the Java interop
guide.
A java.util.ArrayList is created, one element is added, and size returns the
element count.
object may also be a Lisp string, number, character or t, called as the Java object it
becomes for an Object parameter (a string as a String, 42 as an Integer):
The method name may carry the parameter types ("append(CharSequence)"). A call whose
receiver class is known from the text -- (java:new ...), a declared return type,
(the (java:object "C") x) or (declare (type (java:object "C") v)) -- is resolved once,
before it runs, among the methods of that class: to one method when the argument kinds are
known too, otherwise to the overloads it chooses among by the kinds its arguments have when
it runs (the guide's Resolving calls before they
run).
A function argument passed where an interface is expected becomes a java:proxy of it, called with the method name first. Ending the call in :functional, after the arguments, makes it implement each abstract method by the method's arguments instead, as java:new and java:static do with the same ending (the guide's Callbacks via java:proxy).
Ending the call in :java-false, after the arguments (before or after :functional),
answers Java's false as |false| rather than nil (the guide's Java's false
back):
Ending the call in :octets, beside the other markers, answers a byte[] -- the result, or
an element of an array it answers -- as an (unsigned-byte 8) vector of its octets rather
than a list of signed bytes, and hands one to a function the call converts the same way --
Java's own array, so what the function stores Java reads (the guide's Octets back):
Ending the call in :through and a function, beside the other markers, has Java call a
function the call converts through that function: (f function object arguments), object
t when the method answers an object, and the method answers what f answers (the guide's
Calling functions through another).