Functions -
java
| cast |
Returns an |
| createNull |
Returns a |
| fromString |
Returns a |
| getClass |
Returns a |
| isNull |
Returns |
| jObjToString |
Returns the string representation of a Java object stored in a handle reference. |
| toString |
Returns a Ballerina |
Returns an JObject|error, which is obtained after casting the provided JObject instance
to the given JObject type depending on assignability.
JObject|error obj = java:cast(inputStream, typedesc<FileInputStream>);
if (obj is JObject) {
FileInputStream fileInputStream = <FileInputStream>obj;
}
Parameters
- value JObject
-
The
JObjectinstance which is to be casted
- castType typedesc
-
The
typedesc<JObject>to which the given object is casted to if assignable
-
Return Type
(JObject | error) The
JObject|error, which refers to the newJObjectinstance or anerror
Returns a handle, which refers to Java null.
handle nullHandle = java:createNull();
-
Return Type
(handle) The
handle, which refers to Java null
Returns a handle, which refers to the Java string representation of the Ballerina string.
handle header = java:fromString("Content-Type");
Parameters
- value string
-
The Ballerina
stringwith which thehandleis created
-
Return Type
(handle) The
handle, which refers to the Java String representation of the Ballerinastring
Returns a handle, which refers to the Java Class object associated with the class or interface with the given
string name.
handle|error intClass = java:getClass("int");
This function performs a Java class.forName(name) except for the following cases:
| Name | Output |
|---|---|
| boolean | Java Class instance representing the primitive type boolean |
| byte | Java Class instance representing the primitive type byte |
| char | Java Class instance representing the primitive type char |
| short | Java Class instance representing the primitive type short |
| int | Java Class instance representing the primitive type int |
| long | Java Class instance representing the primitive type long |
| float | Java Class instance representing the primitive type float |
| double | Java Class instance representing the primitive type double |
Parameters
- name string
-
The name of the Java class
-
Return Type
(handle | error) The Java Class object for the class with the given name
Returns true if this handle refers to Java null.
boolean status = java:isNull(value);
Parameters
- value handle
-
The
handleof which the referred value is to be tested with Java null
-
Return Type
(boolean) trueif this handle refers to Java null
Returns the string representation of a Java object stored in a handle reference.
Parameters
- jObj handle
-
The
handlereference to the corresponding Java object.
-
Return Type
(string) The
stringrepresentation of the Java object.
Returns a Ballerina string representation of the Java object referred by the handle.
If the handle refers to Java null, then this function returns a nil value.
string? version = java:toString(versionProperty);
Parameters
- value handle
-
The
handleof which the referred value is to be converted to a Ballerinastring
-
Return Type
(string?) The Ballerina
stringrepresentation of the Java object referred by thehandleor else returns()if thehandlerefers to Java null