Learn how to work with Java
Java Wrapper Types general syntax.
1 2 | data X = X @[class-name]
deriving Class
|
1 2 3 4 5 | data JInteger = JInteger @java.lang.Integer
deriving Class
data JIntegerArray = JIntegerArray @java.lang.Integer[]
deriving Class
|
In this example, we’re declaring JWTs for the java.lang.Integer class and the java.lang.Integer[] array (which is technically a class on its own).
1 2 | data X = X @[class-name]
deriving (Class, Eq, Show)
|
Currently, deriving the Class, Eq, and Show instances for JWTs is supported. You should derive these instances based on the need of the application. The Eq instance will use the underlying Object.equals() method and the Show instance will use Object.toString().
When writing FFI declarations, you are essentially specifying the type of a function whose arguments will be translated from Eta types to Java types and whose result will be translated from Java types to Eta types. This translation process is called marshalling. A Java Wrapper Type will marshal to an object of the class given in the definition.
The following table shows a couple of Eta types which aren't JWTs, but still marshal to a Java class or return type:
Java Type | Eta Type |
java.lang.String | String |
Any nullable object X | Maybe X |
void | () |
The following table lists the mapping from primitive Java types to Eta types.
Java Type | Eta Type |
boolean | Bool |
byte | Byte |
short | Short |
char | Char |
int | Int |
long | Int64 |
float | Float |
double | Double |