It may seem a trivial question, but I've searched a lot and couldn't find an answer.
If I have a final field like this:
private final double DEGREES;
The variabile is written in caps because it's final, but shall also the getter method be in caps? So it would be getDEGREES or getDegress?
It should be getDegrees
. And, in my opinion, the only fields that should be in all caps are some static final
ones. Member fields that are final do not need to be in all caps.
/edit
Indeed, Oracle's Java code conventions say to only to have static final
constants in all caps, all member variables should be in lowerCamelCase.
If that is a constant, you can expose it without a getter, as a static field. That seems to be the standard practice.
正确的getter命名约定是getDegrees
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.