Previous: Time-related functions, Up: Miscellaneous [Contents][Index]
These sections document older and less convenient ways to call Java methods, access Java fields, and use Java arrays.
The following lower-level primitives require you to specify
the parameter and return types explicitly.
You should probably use the functions invoke
and invoke-static
(see Method operations) instead.
Returns a new anonymous procedure, which when called will create a new object of the specified class, and will then call the constructor matching the specified argument types.
Returns a new anonymous procedure, which when called will invoke the instance method whose name is the string method in the class whose name is class.
Returns a new anonymous procedure, which when called will invoke the static method whose name is the string method in the class whose name is class.
Returns a new anonymous procedure, which when called will invoke the matching method from the interface whose name is interface.
The macros return procedure values, just like lambda
.
If the macros are used directly as the procedure of a procedure call,
then kawa can inline the correct bytecodes to call the specified methods.
(Note also that neither macro
checks that there really is a method that matches the specification.)
Otherwise, the Java reflection facility is used.
The following macros evaluate to procedures that can be used to access or change the fields of objects or static fields. The compiler can inline each to a single bytecode instruction (not counting type conversion).
These macros are deprecated.
The fields
and static-field
functions
(see Field operations) are easier to use, more powerful, and
just as efficient. However, the high-level functions currently do
not provide access to non-public fields.
Use this to access a field named fname having type type in class class. Evaluates to a new one-argument procedure, whose argument is a reference to an object of the specified class. Calling that procedure returns the value of the specified field.
Use this to change a field named fname having type type in class class. Evaluates to a new two-argument procedure, whose first argument is a reference to an object of the specified class, and the second argument is the new value. Calling that procedure sets the field to the specified value. (This macro’s name does not end in a ‘!’, because it does not actually set the field. Rather, it returns a function for setting the field.)
Like primitive-get-field
, but used to access static fields.
Returns a zero-argument function, which when called returns
the value of the static field.
Like primitive-set-field
, but used to modify static fields.
Returns a one-argument function, which when called sets the
value of the static field to the argument.
The following macros evaluate to procedures that can be used to manipulate primitive Java array objects. The compiler can inline each to a single bytecode instruction (not counting type conversion).
Evaluates to a one-argument procedure. Applying the resulting procedure to an integer count allocates a new Java array of the specified length, and whose elements have type element-type.
Evaluates to a three-argument procedure. The first argument of the resulting procedure must be an array whose elements have type element-type; the second argument is an index; and the third argument is a value (coercible to element-type) which replaces the value specified by the index in the given array.
Evaluates to a two-argument procedure. The first argument of the resulting procedure must be an array whose elements have type element-type; the second argument is an index. Applying the procedure returns the element at the specified index.
Evaluates to a one-argument procedure. The argument of
the resulting procedure must be an array whose elements have type
element-type.
Applying the procedure returns the length of the array.
(Alternatively, you can use (field array 'length)
.)
Previous: Time-related functions, Up: Miscellaneous [Contents][Index]