4 ms·
For where we do use it: * Member variables of a class that should be initialized in the constructor * Static final constants * Any configuration-like variabl
by gamegoblin 11y ago
For where we do use it:
* Member variables of a class that should be initialized in the constructor
* Static final constants
* Any configuration-like variable
* Like you mentioned, when you need to initialize a variable in a particular scope, but the initialization could happen in several control paths of inner scopes
- the_af 11y agoAnd coming full circle with the original question, I'd add: * Function parameters. Re-assigning a variable used as a function parameter is frequently a mistake, and almost always makes code more confusing. I find the "this is defined only once in this function" philosophy to be useful in keeping complexity down in Java programs. Even if final doesn't make objects immutable.