Changing Method Names

ObjectiveCName Annotation

You can annotate any Java method with @ObjectiveCName to change the translated name of that method and any method that overrides it. For example:

@ObjectiveCName("setTimeWithHours:minutes:seconds:")
public void setTime(int hours, int minutes, int seconds) {
  ...
}

is translated as:

- (void)setTimeWithHours:(jint)hours
                 minutes:(jint)minutes
                 seconds:(jint)seconds;

Mapping File

Method names can be changed using the --mapping flag, which takes a properties file with the mappings to use. Each method mapping is defined with the full Java method signature for the key, and an Objective-C selector value. For example, the line to map Object.equals() to NSObject.isEqual: is:

java.lang.Object.equals(Ljava/lang/Object;)Z = isEqual:

The left hand declaration is the full method signature, as defined by the Java Virtual Machine Specification. The right hand definition consists of the iOS selector (i.e. what you would pass to @selector()). The method and its mapping must have the same number of parameters.

As another example, this line is equivalent to the example in the previous section:

pkg.ClassName.setTime(III)V = setTimeWithHours:minutes:seconds:

Additional mapping files can be specified on the command-line, using the --mapping option.