All Manuals > LispWorks User Guide and Reference Manual > 15 Java interface

NextPrevUpTopContentsIndex

15.6 Utilities and administration

Use jobject-p to test whether a Lisp object is a jobject or not.

Use lisp-java-instance-p to test whether the argument is an instance of standard-java-object.

get-jobject returns the jobject for a Java object, nil otherwise, and can be used as predicate to determine whether the argument is a valid Java object. Note that if you have an instance of standard-java-object, get-jobject may return nil if the slot is not set. ensure-is-jobject is like get-jobject, but signals an error if its argument is not a jobject.

jobject-class-name can be use to find the Java class raw name of a Java object. jobject-pretty-class-name makes it "pretty", which matches how it appears in the Java code.

jobject-string returns a string representing the object the way Java wants to represent it (the result of Object.toString).

jobject-to-lisp and lisp-to-jobject can be used to convert between Lisp and Java objects of primitive types, which may sometimes be useful.

find-java-class can used to find the Java class object for class specification, which normally is the string representing the full class name, but can be also be a keyword for specific primitive types.

jobject-of-class-p can be used to verify whether a Java object is an instance of a class or any of its subclasses.

reset-java-interface-for-new-jvm eliminates cached Java objects from internal Lisp structures. It is intended to be used if you need to start a JVM, stop it and start again. Currently there is no interface to stop the JVM.

intern-and-export-list, default-name-constructor, record-java-class-lisp-symbol, ensure-lisp-classes-from-tree and ensure-supers-contain-java.lang.object are utility functions that are used by the definition generation code, and appear in the output of the importing interface (write-java-class-definitions-to-file, write-java-class-definitions-to-stream and generate-java-class-definitions). Their purpose is to be used by the importing interface, but if you find them useful you can call them directly.

get-superclass-and-interfaces-tree returns a tree of the superclasses and interfaces of a Java class. It is also used internally by the importing interface.

send-message-to-java-host can be used to send a message (a string) to the Java host. This is especially useful when the Lisp is used inside Java, for example on Android, so Java needs to do the displaying of messages to the user.

The Java interface currently may generate at runtime specific Java interface conditions of the types below.

Conditions with names ending *-exception are all subclasses of java-exception, and correspond to an exception raised while calling Java. java-exception has two subclasses: java-normal-exception for exceptions that you may get during normal execution, and java-serious-exception, for exceptions that indicate the system is broken in some way. java-serious-exception should never happen, while java-normal-exception may happen in normal code.

The other conditions correspond to errors which are detected inside Lisp.

The java-exception class has three readers, java-exception-string, java-exception-java-backtrace and java-exception-exception-name, which you can use when handling the condition. The macros catching-java-exceptions and catching-exceptions-bind can be used to catch Java exceptions instead of signaling an error. Your code can then access the Java exception directly.

java-interface-error

Superclass of the *-error conditions.

java-definition-error

Superclass of java-class-error and java-method-error.

java-class-error

Class not found.

java-method-error

Method not found.

java-field-error

Field not found, or was defined with the wrong static-p value.

java-field-setting-error

Setting a field failed, either because it is final or an unacceptable value was supplied.

call-java-method-error

call-java-method failed to find the method.

create-java-object-error

create-java-object failed to find constructors.

java-array-error

Superclass of all array errors.

java-out-of-bounds-error

Bad index passed to jvref or jaref, or bad start and end passed to other functions accessing arrays.

java-storing-wrong-type-error

Trying to store value of wrong type into a Java array.

java-exception

Superclass of the *-exception conditions.

java-normal-exception

Superclass of normal exceptions.

java-serious-exception

Superclass of serious exceptions.

Normal exceptions:

field-exception

Superclass of field exceptions.

field-access-exception

Exception accessing a field (maybe wrong type of value).

java-method-exception

Exception inside a call to a Java method.

Serious exceptions:

java-id-exception

Failed to find JNI ID for a method.

java-low-level-exception

Failure in some JNI function.


LispWorks User Guide and Reference Manual - 13 Feb 2015

NextPrevUpTopContentsIndex