Annotations - java

  • Constructor ConstructorData external
  • The Constructor annotation describes a Java constructor that provides an implementation of a Ballerina function whose body is marked as external. If the Ballerina function body is marked as external, it means that the implementation of the function is not provided in the Ballerina source module.

    The following code snippet shows an example usage of this annotation. Here, the newJavaLinkedList Ballerina function's implementation is provided by the default constructor of the java.util.LinkedList class.

     import ballerina/java;
    
     function newJavaLinkedList() returns handle = @java:Constructor {
          class: "java.util.LinkedList"
     } external;
    
  • FieldGet FieldData external
  • The FieldGet annotation describes a Java Field access that provides an implementation of a Ballerina function whose body is marked as external.

  • FieldSet FieldData external
  • The FieldSet annotation describes a Java Field mutate that provides an implementation of a Ballerina function whose body is marked as external.

  • Method MethodData external
  • The Method annotation describes a Java method that provides an implementation of a Ballerina function whose body is marked as external. If the Ballerina function body is marked as external, it means that the implementation of the function is not provided in the Ballerina source module.

    The following code snippet shows an example usage of this annotation. Here, the getUUID Ballerina function's implementation is provided by the java.util.UUID.randomUUID static method.

     import ballerina/java;
    
     function getUUID() returns handle = @java:Method {
         name: "randomUUID",
         class: "java.util.UUID"
     } external;
    

    The name field is optional. If it is not provided, the name of the Java method is inferred from the Ballerina function.