ADC Home > Reference Library > Technical Q&As > Cocoa > Java >

Not Recommended Documentclose button

Important: The information in this document is Not Recommended and should not be used for new development.

Current information on this Reference Library topic can be found here:

Comparing selectors in Cocoa-Java code


Q: I'm comparing an NSSelector in my Cocoa Java code to an action from my nib, and they look like they are equal, but the test for equality fails. Why?

A: Interface Builder is on the other side of the Java Bridge that translates between Objective-C and your Java code, and thus the actions it archives in the nib are saved as Objective-C selectors. At runtime, the Objective-C selectors have names that end in ":" while the Java selectors don't, and thus two selectors that appear to point to the same code fail an equality test against their names. The solution is to check for both flavors of selector (like the following example comparing two actions) or strip off the colons yourself:




    if (someControl.action().name().equals("someActionSelector:")
    || someControl.action().name().equals("someActionSelector")) {

        // do something

    }




[Aug 31 2001]


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.