(java:handle value text &optional hash order class)
(java:handle function :functional :java-false [:octets] [:through f])
Makes a Java object that stands for value, a Lisp value Java has no value of (a symbol, a
list, ...). Java sees text as the object's toString. Two handles of one class and one
text are equals; the object's hashCode is hash's low 32 bits (the text's hashCode
without one), and a handle orders a handle of its class by order (the text without one),
so a handle keys a java.util.HashMap and sorts in a java.util.TreeSet. Wherever Java
hands the handle back -- a method's result, an array's element, a callback's argument --
java: answers value. 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.
(let ((l (java:new "java.util.ArrayList")))
(java:call l "add" (java:handle '(1 2) "pair"))
(list (java:call l "toString") (java:call l "get" 0)))
; => ("[pair]" (1 2))(let ((s (java:new "java.util.TreeSet")))
(java:call s "add" (java:handle 'a "a" 0 "2"))
(java:call s "add" (java:handle 'b "b" 0 "1"))
(java:call s "toString"))
; => "[b, a]"- A nil
hashmakes a handle equal only to an object standing for the very samevalue(eq) under itsclass-- such a handle, ajava:reifygiven:value, the object a function is (java:call) -- itshashCodethe value's identity hash. Itstextmay then be nil: itstoStringisObject's spelling, the class and the hex hash (my.Cell@1b6d3586). ordermay be a function:compareTocalls it with the value and the Lisp value of the object compared with, and answers the sign of the real number it answers. A nilordermakes the handle order nothing. A handle that does not order the object, or meets a handle of anotherclass, throws theClassCastExceptiona cast would (class S cannot be cast to class K).classnames the class Java's messages give the handle, and splits equality and order: handles of two classes are neverequalsand never compare.- A handle of a real number is a
java.lang.Numberof it:doubleValue(a ratio'sDECIMAL64quotient),longValue,intValue.
(let ((s (java:new "java.util.TreeSet"))
(by-value (lambda (r other) (if (realp other) (signum (- r other)) nil))))
(dolist (r (list 1/2 1/3 3/4))
(java:call s "add" (java:handle r (princ-to-string r) 0 by-value "my.Ratio")))
(list (java:call s "toString") (java:call s "first")
(java:call (java:handle 1/3 "1/3" 0 by-value "my.Ratio") "doubleValue")))
; => ("[1/3, 1/2, 3/4]" 1/3 0.3333333333333333)Given a function and, in place of text, a call's markers -- :functional and
:java-false, beside any of :octets and :through f, in any order -- the handle is the
object the function is at a call ending in them (java:call): a Runnable,
Callable and Comparator by the function's arguments, named clojure.lang.AFunction, equal
to every object standing for the function under that class. Java calls it as such a call's
object, through f with resolved nil, since no call chose a member.
(let* ((f (lambda () 42))
(h (java:handle f :functional :java-false))
(l (java:new "java.util.ArrayList")))
(java:call l "add" h)
(list (java:call h "call") (eq f (java:call l "get" 0))))
; => (42 T)A text that is no string (or nil with a hash), a hash that is no integer or nil, an
order that is no string, function or nil, or a class that is no string or nil is an
error: java:handle expects (java:handle value text [hash [order ["class"]]]), got 2, and so
is a value no function before the markers: java:handle expects (java:handle function :functional :java-false [:octets] [:through f]), got 5. The object is of
am.ik.rontolisp.runtime.RontoJavaHandle (RontoJavaNumberHandle for a number), a class the
interpreter uses too and a compiled program ships beside it, made with no reflection. The
object a function is is of a class a compiled program generates, and a
java.lang.reflect.Proxy on the interpreter and where the :through function is no literal
#'name. See also java:view.