(rontolisp) docs
← java Package Functions

java:new

(java:new "fully.qualified.ClassName" args...)

Constructs a host (Java) object by reflection, choosing the constructor whose parameters best match the arguments, and returns an opaque java object that prints as #<java <class-name>>. Part of the JVM-only java interop package — available on the interpreter and in JVM-compiled classes, not on the WASM backend, and it needs the class to be present and reflectable at runtime. See the Java interop guide.

A java.lang.StringBuilder is constructed from the string "ab", then its length method returns 2.

The class name may carry the constructor's parameter types, which picks it directly: (java:new "java.lang.StringBuilder(int)" 64). A call is resolved once, before it runs: to one constructor when its argument kinds are known from the text, otherwise to the constructors it chooses among by the kinds its arguments have when it runs (the guide's Resolving calls before they run).

The arguments may be followed by :functional, which converts a function argument the way Java converts a lambda (the guide's Callbacks via java:proxy), by :java-false, which hands such a function Java's false as |false| (the guide's Java's false back), by :octets, which hands it a byte[] as an (unsigned-byte 8) vector of its octets (the guide's Octets back), and by :through and a function, through which Java calls such a function (the guide's Calling functions through another).