Annotations - java

  • Binding ObjectData class
  • Describes the Java class representing a Ballerina binding.

     @java:Binding {
       'class: "java.io.File"
     }
    
  • Constructor ConstructorData external
  • Describes a Java constructor, which provides an implementation of a Ballerina function of which the 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.

     function newJavaLinkedList() returns handle = @java:Constructor {
          'class: "java.util.LinkedList"
     } external;
    
  • FieldGet FieldData external
  • Describes a Java Field access, which provides an implementation of a Ballerina function of which the body is marked as external.

     function getError() returns handle = @java:FieldGet {
         name:"err",
         'class:"java/lang/System"
     } external;
    
  • FieldSet FieldData external
  • Describes a Java Field mutate, which provides an implementation of a Ballerina function of which the body is marked as external.

     function setContractId(handle contractId) = @java:FieldSet {
       name:"contractId",
       'class:"org/lang/impl/JavaFieldAccessMutate"
     } external;
    
  • Method MethodData external
  • Describes a Java method, which provides an implementation of a Ballerina function of which the 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.

     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.