Next: , Previous: Using pragma foreign_proc for Java, Up: Interfacing with Java   [Contents] Using pragma foreign_export for Java

A ‘pragma foreign_export’ declaration for Java has the form:

:- pragma foreign_export("Java", MercuryMode, "Java_Name").

For example,

:- pragma foreign_export("Java", foo(in, in, out), "FOO").

The type signature of the Java interface to a Mercury procedure is as described in Java data passing conventions.

Calling polymorphically typed Mercury procedures from Java is a little bit more difficult than calling ordinary (monomorphically typed) Mercury procedures. The simplest method is to just create monomorphic forwarding procedures that call the polymorphic procedures, and export them, rather than exporting the polymorphic procedures.

If you do export a polymorphically typed Mercury procedure, the compiler will prepend one ‘type_info’ argument to the parameter list of the Java interface function for each distinct type variable in the Mercury procedure’s type signature. The caller must arrange to pass in appropriate ‘type_info’ values corresponding to the types of the other arguments passed. These ‘type_info’ arguments can be obtained using the Mercury ‘type_of’ function in the Mercury standard library module ‘type_desc’.