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


Arguments: name (lisp-class &rest argtypes) &optional retmod

This macro defines a Lisp method where the first argument is specialized on a class defined with def-java-class. The first argument determines the name of the Lisp function and of the corresponding Java method.

If the argument is a single symbol, it is used as the name of the Lisp method and the symbol-name is used as the name of the Java method.

If the first argument is a list, the first element in the list is a symbol, the name of the Lisp function, and the second element is a symbol or a string, the name of the Java method.

If symbols are used to name Java methods, the symbol-name is used without any case conversion. In modern mode, this is likely to be correct and useful, but in ANSI mode it will usually be in the wrong case unless escape characters are used as needed.

The first item in the second argument is the name of a class previously defined with def-java-class. The remaining items in the second argument are strings or symbols that denote Java classes.

If the third argument is specified, it is a call modifier that is appended to every call on the Java method. If the call has an explicit modifier, the modifier in this definition is ignored.

The defined Lisp method expects as its first argument an instance of the Lisp class. Only the first argument is used to dispatch the method, the remaining arguments are bound to an &rest argument. Therefore, if two Java methods with the same name and in the same class are defined with def-java-method, they must have distinct Lisp names.


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

    (append-str "append") 
    (string-buffer "java.lang.String"))
    (append-chr "append") 
    (string-buffer "char")) 

The above forms define Lisp methods that call the corresponding Java methods. Although these are generic functions, they still must have distinct names because we only dispatch on the first (instance) argument. If another Java class has similarly named methods, lisp methods named append-str and append-chr could be defined for that class without causing any conflicts.

The Lisp methods are called with forms such as:

(setf x (new-string-buffer-int 17))
(append-str x "abc")
(append-chr x #\d)

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.

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