Javabean convention - a method that calls the gId property

If I have a gId property in my Java class, then which access method should be named like?

getGId is what I assume.

If the gURL property gURL , I think it would be getGURL , which looks ugly (not referring to the alternative spelling of the girl, though).

If the property was just a url , the getUrl method getUrl good on the eye, and yes, I would not name the property as a URL in the first place, which would make the accessory ugly again - getUrl

I remember reading from the Javabean Specification PDF somewhere about capitalizing properties, as well as cases containing abbreviations, but could not find it in PDF anymore.

Does anyone have a link to it or please confirm if I am correct in what I say?

+3
source share
2 answers

The link you are interested in can be found in the Beans specification in section 8.8.

However, it clearly does not cover your particular case of gId / gURL . The specification says that to provide a getter / setter we just use the first letter. To restore a property from a getter / setter, if the first two letters are uppercase, then the whole property remains as it is. Otherwise, we decapitalize the first letter. Thus, your recipient will become getGURL , but your property will be incorrectly restored from getter as gURL . You have the same problem with gId .

Therefore, it seems that the specification does not allow for a consistent translation of any property with the first lowercase character followed by an uppercase character.

My suggestion is to either accept the full lowercase property, or expand the line prefix by two letters ( glURL , for example).

+6
source

To be more specific (and as Luca said here as well ), spec says there is a way that can tell you: java.beans.Introspector.decapitalize (String) .

0
source

All Articles