MacroPackage: net.jlinkerToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.1
Unrevised from 10.0 to 10.1.
10.0 version

def-java-class

Arguments: name supers statics fields slots &rest options

This macro defines a Lisp class that represents a Java class. Once a Lisp class is defined to represent a Java class, remote references to instances of the Java class will be instances of the corresponding Lisp class. As a result, Lisp methods may be defined.

If the name is a string or symbol, it is the name of the Java class and the corresponding symbol is the name of the Lisp class. If the name is a list, the first element is a symbol for the name of the Lisp class and the second element is a string or symbol that identifies a Java class. The name may also be a list of three or more elements; in this case, the first element is the name of the Lisp class, the second element is the name of the base Java class or interface, and the remaining elements are the names of derived Java classes. The derived Java classes must all inherit from the base Java class or interface. Any instances of the derived or base Java classes will be mapped to the Lisp class.

The second argument is a list of Lisp superclasses. This list will be augmented by adding the class net.jlinker::java-class at the end.

The third and fourth arguments are lists of static and class fields in the Java class. Each item is of the form

(name [:accessor aname] [:reader rname] [:writer wname])

where name is again like the class name - a single string or symbol or a list of two. If the accessor, reader and writer components are omitted, the Lisp name of the field is defined as an accessor to the Java field. If any of the accessor, reader and writer components are specified, then those are the only accessors defined for the field.

The fifth argument is additional Lisp slots that are added to the class with no inspection of any kind. The final optional arguments are appended to the class definition.

Examples

(def-java-class (gcal "java.util.GregorianCalendar") ()
    (((gcal-friday "FRIDAY") :reader gcal-friday)
     ((gcal-ad     "AD")     :reader gcal-ad))
    ()
    ())

This form defines a Lisp class gcal that will be used to represent any remote references to instances of the Java class java.util.GregorianCalendar. The Lisp functions gcal-friday and gcal-ad (both of zero arguments) are accessors for the static fields FRIDAY and AD in the Java class.

(defclass application-buffer () ((source :initform "Lisp")))

(def-java-class (string-buffer "java.lang.StringBuffer")
(application-buffer)
    ()
    ()
    ((source :initform "Java")))

This form defines a Lisp class string-buffer that will be used to represent any remote references to instances of the Java class java.lang.StringBuffer. The slot named source does not exist in the Java object, but is present on every remote reference to a Java object of that class. This example also shows how a remote reference may inherit from other Lisp classes.

See jlinker.htm for more information on the jLinker facility.


Copyright (c) 1998-2022, Franz Inc. Lafayette, CA., USA. All rights reserved.
This page was not revised from the 10.0 page.
Created 2019.8.20.

ToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.1
Unrevised from 10.0 to 10.1.
10.0 version