google / google/styleguide

Java Style Guide: Constants example (Joiner vs Logger)

Open
#303 7 comments 0 reactions 0 assignees View on GitHub
lang:java
Dominant language
HTML
Stars
39.6k
Forks
12.9k
Avg merge
42m
Merged PRs (30d)
15

Description

I've seen many discussions about if a `static final Logger` instance should be considered a constant or not (i.e. uppercase letters), and there are references to this style guide in which is suggested to use the logger as a non-constant value:

```
static final Logger logger = Logger.getLogger(MyClass.getName());
```

However, in most of the cases (at least all that I know), the `Logger` instances are immutables because there are no methods to change the internal status or to retrieve a mutable object, which seems to be the same case of the `Joiner`:
```
static final Joiner COMMA_JOINER = Joiner.on(','); // because Joiner is immutable
```

What is the fundamental difference between a `Logger` and a `Joiner` to differentiate them as a constant or non-constant?

What would be the case of a `Gson` instance if declared as a `static final`?

Thanks in advance

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.