Naming convention for objects in java

后端 未结 6 672
-上瘾入骨i
-上瘾入骨i 2021-01-04 09:12

I had started programming in java 2 years back. Seniors in our project at that time had advised me to append \'obj\' to the name of the object which is being created.

<
6条回答
  •  时光取名叫无心
    2021-01-04 09:48

    Your example is a bit too trivial. In reality you would never name a field of object type "Car" as "car". Likewise you never name an "Integer" type as "integer".

    Instead, the use names that tell the reader what the field is used for. Some examples:

    private Transport preferredTransportMethod;
    
    private int invoiceCounter;
    

    Prefixing field type is not used commonly is Java. However, class member are sometimes prefixed with lower case "m" to prevent accidental self assignments in setter methods.

    private long mTripDurationMillis;
    

提交回复
热议问题