BBB : User's guide : Java Binding - urschleim/scream GitHub Wiki

Object system

Operations

scream offers a simple but powerful interface to the Java object system.

The syntax (make-object ... is used in various forms to create a Java-object.

  • (make-object symbolic-java-class-name) -- Creates an object representing a class instance of symbolic-java-class-name.
  • (make-object (symbolic-java-class-name)) -- Calls the default (parameterless) constructor to create an object of the passed symbolic-java-class-name.
  • (make-object (symbolic-java-class-name ctor-arg₁ ...)) -- Calls the constructor of the passed symbolic-java-class-name that matches the passed parameter types.

All operations return a value of type object. The (object? obj) can be used to check if a certain value represents an object. Object-typed values are functions and can be used to interact with the Java-object. Assume for the following that a Java-object has been successfully created by the following code:

(define obj
  (make-object (java.class.Name ...)))

After that, the following operations are possible:

  • (obj symbolic-property-name) -- returns the value of the member-variable symbolic-property-name.
  • (obj symbolic-property-name new-value) -- sets the value of the member-variable symbolic-property-name to new-value.
  • (obj (operation-name arg₁ ...) -- calls the operation obj.operation-name with the passed argument list.

Type mappings

From Scheme to Java (mapping is implemented in SchemeObject#convertScreamToJava).

Epected Java type Required Scheme type Remark
any Scheme value () An empty list matches all object types.
boolean boolean
byte integer [-128..127]
short integer [-32768..32767]
int integer [-2147483648 ..2147483647]
long integer
float real
double real
char character
java.lang.String string
fcos.FirstClassObject no conversion required This is used if Java-operations are called that know sream's internal type system.
array[] vector