Did a few searched on the inter-webs and could not find an easy answer for this. My problem set is using Java within the Android Framework, but I believe this is just standard Java behavior as well. I understand the definitions of final
and private
, both used for variable access and modifiers. I was following some code and tutorials when the instructions asked me to initialize a variable as a final private
variable. Not having seen this before, I instead made a private final
variable. Later on, the code asked me to initialize the variable in a constructor, which obviously fails against a private final
variable as it is immutable. HOWEVER, it did not fail when I changed the variable to a final private
... which made me interested. Does anyone have ideas why this is the case?
Thanks for the responses!
The Java Language Specification, section 8.3.1. Field Modifiers, says:
FieldModifier: (one of) Annotation public protected private static final transient volatile
If two or more (distinct) field modifiers appear in a field declaration, it is customary, though not required, that they appear in the order consistent with that shown above in the production for FieldModifier.
Which means that private final
is the preferred style, but it's exactly the same as final private
.