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:
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:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003eThe \u003ccode\u003e@ObjectiveCName\u003c/code\u003e annotation allows developers to rename Java methods and their overrides within the translated Objective-C code.\u003c/p\u003e\n"],["\u003cp\u003eMethod renaming can also be accomplished using mapping files specified with the \u003ccode\u003e--mapping\u003c/code\u003e flag during translation, providing an alternative to annotations.\u003c/p\u003e\n"],["\u003cp\u003eMapping files utilize a key-value structure where the key is the Java method signature and the value is the desired Objective-C selector, ensuring both have the same parameter count.\u003c/p\u003e\n"]]],["The `@ObjectiveCName` annotation renames Java methods in their Objective-C translation. The annotation's string value defines the desired Objective-C selector, excluding parameter types and names. Alternatively, the `--mapping` flag utilizes a properties file to map Java method signatures to Objective-C selectors. Each mapping specifies the full Java method signature on the left and the Objective-C selector on the right. Multiple mapping files can be provided. Mapped methods must have the same number of parameters.\n"],null,["# Changing Method Names\n\nObjectiveCName Annotation\n-------------------------\n\nYou can annotate any Java method with\n[@ObjectiveCName](/j2objc/reference/annotations/objectivecname) to change the translated name of\nthat method and any method that overrides it. For example: \n\n @ObjectiveCName(\"setTimeWithHours:minutes:seconds:\")\n public void setTime(int hours, int minutes, int seconds) {\n ...\n }\n\nis translated as: \n\n - (void)setTimeWithHours:(jint)hours\n minutes:(jint)minutes\n seconds:(jint)seconds;\n\n| **Note:** The string value in the annotation is the desired Objective-C selector. Parameter types and names are excluded.\n\nMapping File\n------------\n\nMethod names can be changed using the **--mapping** flag, which takes a properties file with the\nmappings to use. Each method mapping is defined with the full Java method signature for the key, and\nan Objective-C selector value. For example, the line to map Object.equals() to NSObject.isEqual:\nis: \n\n java.lang.Object.equals(Ljava/lang/Object;)Z = isEqual:\n\nThe left hand declaration is the full method signature, as [defined by the Java Virtual Machine\nSpecification](http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.3.4). The right\nhand definition consists of the iOS selector (i.e. what you would pass to @selector()).\nThe method and its mapping must have the same number of parameters.\n\nAs another example, this line is equivalent to the example in the previous section: \n\n pkg.ClassName.setTime(III)V = setTimeWithHours:minutes:seconds:\n\nAdditional mapping files can be specified on the command-line, using the --mapping option."]]