0

I have the following field in Flex:

[Bindable] public var zIndex:uint;

And I was trying to create the methods to process the calls in Java and I ran into a problem.

1. public int getZIndex(); // Does not work.
2. public int getzIndex(); // Works.

I thought that the letter following the get/set was supposed to be capitalized? Is there a reason for this? I couldn't find any documentation.

I found an answer on StackOverflow that states that the first one is the correct way to name an accessor/mutator.

1

Found the answer after some further investigation.

[I]f the first two characters of the name are both upper case and if so leave it alone.

Section 8.8 of the JavaBean Spec by Sun states:

8.8 Capitalization of inferred names.

When we use design patterns to infer a property or event name, we need to decide what rules to follow for capitalizing the inferred name. If we extract the name from the middle of a normal mixedCase style Java name then the name will, by default, begin with a capital letter.

Java programmers are accustomed to having normal identifiers start with lower case letters. Vigorous reviewer input has convinced us that we should follow this same conventional rule for property and event names.

Thus when we extract a property or event name from the middle of an existing Java name, we normally convert the first character to lower case. However to support the occasional use of all upper-case names, we check if the first two characters of the name are both upper case and if so leave it alone. So for example,

      "FooBah" becomes "fooBah"
      "Z" becomes "z"
      "URL" becomes "URL"

We provide a method Introspector.decapitalize which implements this conversion rule.

JavaBeans Introspection -- Sun Microsystems -- 10/12/97

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.