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

NextPrevUpTopContentsIndex

jobject-to-lisp

Function
Summary

Converts a jobject to a Lisp object where possible.

Package

lw-ji

Signature

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

Arguments

object

A jobject or nil.

nil-when-fail

A generalized boolean.

Values

lisp-object

A Lisp object.

Description

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 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.

Notes

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)
      (fail-branch)
    (success-branch)))

LispWorks User Guide and Reference Manual - 20 Sep 2017

NextPrevUpTopContentsIndex