[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
28.4.2 Declaring Java classes
The <declare-class-clause> clause denotes importation of Java classes.
<declare-class-clause> →(
class <typed-ident> <slot>* <string>)
<slot> → <field> | <method> | <constructor> <field> →(field
<modifier> <typed-ident> <string>)
<method> →(method
<modifier> <typed-ident>(
<typed-ident>*)
<string>)
<constructor> →(constructor
<ident>(
<typed-ident>*))
<modifier> →public
|private
|protected
|static
|final
|synchronized
|abstract
When the compiler encounters a Java class declaration, it automatically
creates a predicate. If the class identifier is id
, the predicate
is named id?
. In addition, the compiler generates functions that
fetch and set the field values. For a field named f
, these functions
are named id-f
and id-f-set!
. Methods and constructors are
also always prefixed the name of the class. That is, for a method named
m
of a class k
, the Scheme name of the method is k-m
.
Example:
(module java-example (java (class point (constructor new-default ()) (field x::int "x") (method show::void (::point) "show") (method static statistics::int () "PointStatistics") "Point") (class point-3d::point "Point3D"))) (let ((p (point-new-default))) (print (point? p)) -|#t
(point-x-set! p 3) (print (point-x p))) -|3
This document was generated on March 31, 2014 using texi2html 5.0.