Functions - java

createNull
Returns a handle, which refers to Java null.
fromString
Returns a handle, which refers to the Java string representation of the Ballerina string.
getClass
Returns a handle, which refers to the Java Class object associated with the class or interface with the given string name.
isNull
Returns true if this handle refers to Java null.
toString
Returns a Ballerina string representation of the Java object referred by the handle.

createNull

()

returns handle
Returns a handle, which refers to Java null.
 handle nullHandle = java:createNull();
  • Return Type

    (handle)
  • The handle, which refers to Java null

fromString

(string value)

returns handle
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 string with which the handle is created

  • Return Type

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

getClass

(string name)

returns handle | error
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:
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

(handle value)

returns boolean
Returns true if this handle refers to Java null.
 boolean 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

(handle value)

returns string?
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 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