Functions

cast
I

Performs a Java cast operation on a value.

createNull
I

Returns a handle, which refers to Java null.

fromString
I

Returns a handle, which refers to the Java string representation of the Ballerina string.

getClass
I

Returns a handle, which refers to the Java Class object associated with the class or interface with the given string name.

isNull
I

Returns true if this handle refers to Java null.

toString
I

Returns a Ballerina string representation of the Java object referred by the handle.

cast

function cast(JObject value, typedesc<JObject> t) returns t | error
Isolated Function

Performs a Java cast operation on a value. This casts a value describing a JObject to a type describing a JObject based on Java assignability, returns an error if the cast cannot be done.

1FileInputStream|error obj = java:cast(inputStream);

Parameters

  • value JObject
  • A value describing a JObject which is to be casted

  • t typedesc<JObject> (default <>)
  • A type describing a JObject to which the value is to be casted

Return Type

(t | error)

A value belonging to type t or an error if this cast cannot be done

createNull

function createNull() returns handle
Isolated Function

Returns a handle, which refers to Java null.

1handle nullHandle = java:createNull();

Return Type

(handle)

The handle, which refers to Java null

fromString

function fromString(string value) returns handle
Isolated Function

Returns a handle, which refers to the Java string representation of the Ballerina string.

1handle header = java:fromString("Content-Type");

Parameters

  • value string
  • The Ballerina string with which the handle is created

Return Type

(handle)

The handle, which refers to the Java String representation of the Ballerina string

getClass

function getClass(string name) returns handle | error
Isolated Function

Returns a handle, which refers to the Java Class object associated with the class or interface with the given string name.

1handle|error intClass = java:getClass("int");

This function performs a Java class.forName(name) except for the following cases:

NameOutput
booleanJava Class instance representing the primitive type boolean
byteJava Class instance representing the primitive type byte
charJava Class instance representing the primitive type char
shortJava Class instance representing the primitive type short
intJava Class instance representing the primitive type int
longJava Class instance representing the primitive type long
floatJava Class instance representing the primitive type float
doubleJava 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

isNull

function isNull(handle value) returns boolean
Isolated Function

Returns true if this handle refers to Java null.

1boolean status = java:isNull(value);

Parameters

  • value handle
  • The handle of which the referred value is to be tested with Java null

Return Type

(boolean)

true if this handle refers to Java null

toString

function toString(handle value) returns string?
Isolated Function

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.

1string? version = java:toString(versionProperty);

Parameters

  • value handle
  • The handle of which the referred value is to be converted to a Ballerina string

Return Type

(string?)

The Ballerina string representation of the Java object referred by the handle or else returns () if the handle refers to Java null