All Manuals > LispWorks® User Guide and Reference Manual > 39 The LW-JI Package

jobject-to-lisp Function


Converts a jobject to a Lisp object where possible.




jobject-to-lisp object &optional nil-when-fail => lisp-object

A jobject or nil.
A generalized boolean.
A Lisp object.

The function jobject-to-lisp converts a jobject to a Lisp object where possible.

The argument object must be a jobject or nil, otherwise an error is signaled. If object is nil, jobject-to-lisp returns nil. If object is a jobject of type java.lang.String or any of the primitive types, jobject-to-lisp returns the matching Lisp object. See 15.1 Types and conversion between Lisp and Java for a full description.

If the conversion cannot be done, the return value depends on the value of nil-when-fail. When nil-when-fail is true jobject-to-lisp returns nil for failure. When nil-when-fail is false, jobject-to-lisp returns the jobject itself. The default value of nil-when-fail is true.


You need to pass nil-when-fail as nil for the cases when you want to be able to distinguish between return value nil for the Java boolean false and failure to convert. When you do that, the caller code needs to compare the result to the argument, instead of checking for non-nil, like this:

(let ((my-res (jobject-to-lisp my-obj nil)))
  (if (eq my-obj my-res)

LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:46