Java: accessory naming convention

I am looking for a formal Java naming convention regarding accessories.

I saw that, for example, the class JPanelabandoned the method size()in favor getSize().

But in the classroom ArrayListmethod size().

So I wonder if accessors should be used getXXX()or xXX()?

+5
source share
7 answers

It is usually a bad idea not to use the JavaBeans (getters and setters) convention.
They are used by reflecting many frameworks, in particular with EL, where sometimes you canโ€™t access your fields without right getters (depending on the taste of EL).

So your accessors should always be named getXxx()or isXxx()and setXxx().

size()in the structure of the collection is an example of a "flaw" that can annoy developers (see link below). The choice made by Josh Bloch and Neil Gufter to make it more readable now makes it difficult to obtain in some contexts (EL).

But remember, the JavaBeans convention is not a Java naming convention.


Resources:

:

+11

getXXX , , . size() , , . getSize(), , - ( ).

+3

-, JavaBean, getXXX isXXX. ( , hasXXX ... .)

a JPanel bean - .., ArrayList.

getXXX , , ArrayList.

+1

, , , :

  • public Type getProperty(). , , .
  • public void setProperty(Type value)

JavaBean. JavaBeans , , : public YourJavaBean withProperty(Type value). , YourJavaBean .

+1

Eclipse , , get. , get set.

0

get/is/set -Convention ( ValueObjects/DataObjects) , JavaBeans, - .

  • "" .
  • JSP , .
0

setXXX getXXX JavaBeans. size(), , , .

0

All Articles