Annotation Type Msg


@Retention(RUNTIME) @Target(METHOD) public @interface Msg
An annotation that allows a Java method to receive and process Objective-C messages. This annotation is only useful for subclasses of ca.weblite.objc.NSObject.

Example Class Using Annotation TO Handle Objective-C messages

The following is some test code that uses the TestClass. Notice that this class can be interacted with the same as if it was an Objective-C object. Indeed, Objective-C can call any of the methods marked by the @Msg annotation by simply sending it the appropriate message.

  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The name of the objective-c selector that can be used to target this method.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Specifies that the signature should match that of another object's method.
    The signature of this message.
  • Element Details

    • selector

      String selector
      The name of the objective-c selector that can be used to target this method. Selectors should be the full method name, including colons. If you're overriding the NSSavePanel's -setTitle: message, then the selector would be "setTitle:". The -title message, on the other hand would just be "title" (without colon) because it takes no parameters.
      Returns:
      the selector name
    • signature

      String signature
      The signature of this message. This should be a valid Objective-C type encoding. If this parameter is omitted, then you can optionally use the like() directive specify that the signature should be the same as another Class' method.
      Returns:
      The signature of the message.

      Example Signatures

      Method Type Signature Explanation
      Returns NSString, takes no parameters @@: The first "@" indicates the return value, which is an Object, The second "@" is a mandatory hidden parameter that refers to the receiver of the message. The ":" is a hidden parameter that refers to the selector of the message.
      Returns void, takes an NSString as a parameter v@:@ The "v" indicates that there is no return value (i.e. void). The first "@" marks the hidden parameter that is the target of the message. The ":" marks the hidden selector. The final "@" indicates that it takes an object as a parameter (specifically an NSString, but the signature doesn't distinguish.
      Returns void, takes an C String (i.e. *char) as a parameter v@:* The "v" indicates that there is no return value (i.e. void). The first "@" marks the hidden parameter that is the target of the message. The ":" marks the hidden selector. The final "*" indicates that it takes a C String as the first parameter.
      See Also:
      Default:
      ""
    • like

      String like
      Specifies that the signature should match that of another object's method. This can make it easier for you to define methods without having to know how to formulate the signature.

      E.g., if you have a method that takes no input, and returns an int, you might just say that your method is like the NSArray.count selector: {@literal @}Msg(selector="myIntMessage", like="NSArray.count")

      Returns:
      The name of a method whose signature that this message should copy.
      Default:
      ""