The following table lists the possible values of arguments of the
argument type specification to jasper_call/4
and
jasper_new_object/5
(see Jasper Library Predicates). The
value specifies which conversion between corresponding Prolog
argument and Java type will take place.
There is currently no mechanism for specifying Java arrays in this way.
In the following the package prefix (java/lang
or
se/sics/jasper
) has been left out for brevity.
For several of the numerical types there is the possibility that the target type cannot accurately represent the source type, e.g. when converting from a Prolog integer to a Java byte. The behavior in such cases is unspecified.
Prolog: +integer
Java: int
int
, a 32 bit signed integer.
Prolog: +byte
Java: byte
byte
.
Prolog: +short
Java: short
short
, a 16 bit signed integer.
Prolog: +long
Java: long
long
, a 64-bit signed integer.
In SICStus versions prior to 3.9.1, the value was truncated to 32 bits
when passed between Java and Prolog. This is no longer the case.
Prolog: +float
Java: float
float
.
Prolog: +double
Java: double
double
.
Prolog: +term
Java: SPTerm
SPTerm
.
Prolog: +object(
Class)
Java:
ClassClass
.
Prolog: +atom
obsolescentJava: SPCanonicalAtom
SPCanonicalAtom
. Often +string
,
see below, is more useful.
Prolog: +boolean
Java: boolean
true
,false
}. The Java method will receive a
boolean
.
Prolog: +chars
Java: String
String
.
Prolog: +codes
Java: String
+codes
is an alias for +chars
.
Prolog: +string
Java: String
String
.
Note.
+chars
, +codes
or +string
the
automatic type conversion mechanism will also create a type signature
of the form java/lang/String. If you want to call a method that
accepts a String object as a parameter, but has different signature,
the method lookup will fail. A workaround is to explicitly create a
String object and then call the method. For example:
:- use_module(library(jasper)). main :- jasper_initialize([],JVM), jasper_new_object(JVM, 'java/lang/String', init(+chars), init("hamburger"), H), Str = "urge", jasper_new_object(JVM, 'java/lang/String', init(+chars), init(Str), S), jasper_call(JVM, method('', contains, [instance]), contains(+object(''), +object('java/lang/CharSequence'), [-boolean]), contains(H, S, B)), format('Contains? ~a~n', [B]).
Prolog: -atom
obsolescentJava: SPTerm
SPTerm
, which
should be set to an atom (e.g. using
SPTerm.putString
). The argument will be bound to the
value of the atom when the method returns. Often -term
, see
below, is more useful.
Prolog: -chars
Java: StringBuffer
StringBuffer
, which can be modified. The argument will be
bound to a code-list of the StringBuffer
object.
Prolog: -codes
Java: StringBuffer
-codes
is an alias for -chars
.
Prolog: -string
Java: StringBuffer
StringBuffer
,
which can be modified. The argument will be bound to an
atom converted from the StringBuffer
object.
Prolog: -term
Java: SPTerm
SPTerm
, which can
be set to a term (e.g. using SPTerm.consFunctor
). The
argument will be bound to the term when the method
returns.
Prolog: [-integer]
Java: int
M()
int
. The value will be converted
to a Prolog integer.
Prolog: [-byte]
Java: byte
M()
byte
. The value will be converted
to a Prolog integer.
Prolog: [-short]
Java: short
M()
short
. The value will be converted
to a Prolog integer.
Prolog: [-long]
Java: long
M()
long
, a 64 bit signed integer.
The value will be converted to a Prolog integer.
Prolog: [-float]
Java: float
M()
float
. The value will be converted
to a Prolog float.
Prolog: [-double]
Java: double
M()
double
. The value will be converted
to a Prolog float.
Prolog: [-term]
Java: SPTerm
M()
SPTerm
, which
will be converted to a Prolog term.
Prolog: [-object(
Class)]
Java: SPTerm
M()
Prolog: [-atom]
obsolescentJava: SPTerm
M()
SPCanonicalAtom
,
which will be converted to a Prolog atom. Often [-term]
,
see above, is more useful.
Prolog: [-boolean]
Java: boolean
M()
boolean
. The value will be converted to
a Prolog atom in {true
,false
}.
Prolog: [-chars]
Java: String
M()
String
, which
will be converted to a code-list.
Prolog: [-codes]
Java: String
M()
[-codes]
is an alias for [-chars]
.
Prolog: [-string]
Java: String
M()
String
, which
will be converted to an atom.