www.delorie.com/gnu/docs/kawa/kawa_65.html   search  
 
Buy GNU books!


Kawa, the Java-based Scheme system

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

10.5 Accessing fields of Java objects

Kawa has both a high-level interface and a low-level interface for accessing the fields of Java objects and static fields. The lower-level interfaces are macros that return functions. These functions can be inlined, producing efficient code. The higher-level functions are less verbose and more convenient. However, they can only access public fields.

Function: field object fieldname
Get the instance field with the given fieldname from the given Object. Returns the value of the field, which must be public. This procedure has a setter, and so can be used as the first operand to set!.

The field name is "mangled" (see section 10.2 Mapping Scheme names to Java names) into a valid Java name. If there is no accessible field whose name is "fieldname", we look for a no-argument method whose name is "getFieldname".

If object is a primitive Java array, then fieldname can only be 'length, and the result is the number of elements of the array.

Function: static-field class fieldname
Get the static field with the given fieldname from the given class. Returns the value of the field, which must be public. This procedure has a setter, and so can be used as the first operand to set!.

Examples:
 
(static-field <java.lang.System> 'err)
;; Copy the car field of b into a.
(set! (field a 'car) (field b 'car))

Function: slot-ref object fieldname
A synonym for (field object fieldname).

Function: slot-set! object fieldname value
A synonym for (set! (field object fieldname) value).


  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003