(rontolisp) docs
← java Package Functions

java:view

(java:view value items shape &optional printer order class)

Makes a read-only Java collection that stands for value: its elements are items converted as Object arguments are, once, when it is made -- or, with :bytes, the byte[] an octet vector is to Java. shape is a keyword:

shapeJava objectitems
:lista java.util.Lista proper list or a vector
:vectora java.util.List that is also RandomAccess and Comparablea proper list or a vector
:seta java.util.Set, a repeated element oncea proper list or a vector
:mapa java.util.Mapa hash table, or a plist
:bytesnone: the byte[] of the octetsan (unsigned-byte 8) vector

Java reads it through those interfaces: equals and hashCode follow their contracts, and every write throws UnsupportedOperationException. Its toString is what (printer value) answers (the Java spelling without a printer). A :vector view orders by order, called with the value and the Lisp value of the object compared with, as a java:handle's order function is; without one it orders nothing. class names the class Java's messages give the view. Wherever Java hands a view back, 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.

As an argument a view is a host object of its class, passed itself wherever its class fits (List, Collection, Iterable, Object, ...). Where a Java array is expected, a :list or :vector view converts to an array of its items -- but only after every way to pass it whole, so a varargs method holds it as one element. A :set or :map view converts nowhere else.

A :bytes view is no collection, and Java never holds it: wherever a byte[] fits -- a byte[] parameter, an Object, Cloneable or Serializable one, an element of another view -- Java is handed the byte[] of its octets, and nowhere else does the view convert. That array is the vector's own storage, so what Java stores into it, then or later, the vector holds, and a vector handed twice to one call is one array to Java. Its printer and class are not used. A byte[] comes back as an octet vector at a call ending in :octets.

A shape that is none of the five, items that are no sequence (a :map's no hash table or plist of even length, a :bytes view's no (unsigned-byte 8) vector), a printer that is no function or nil, an order that is no function or nil (a function only for a :vector), or a class that is no string or nil is an error: java:view expects (java:view value items :list|:vector|:set|:map|:bytes [printer [order ["class"]]]), got :TREE; an item that converts to no Object is java:view: no Java value for X. The object is of an am.ik.rontolisp.runtime.RontoJava*View class, which the interpreter uses too and a compiled program ships beside it, made with no reflection.