We use Google Style conventions with 4 spaces (instead of 2) for indentation. Other extensions and changes are described below.
Table of contents
- Javadocs
- Using
varkeyword - Dealing with
nulls - Returning collections
- Suppressing
uncheckedwarnings using annotation
See Javadoc page for details.
Use the var keyword everywhere it's possible. It makes the code more readable and concise.
This annotation must be set in package-info.java of all the packages.
Everything which is not annotated with @Nullable is not null by default.
Non-nullity of parameters should be checked in public and protected methods to catch incorrect use of the API as early as possible.
If a method accepts two or more parameters that cannot be null, we call Preconditions.checkNotNull() in the order of parameters. checkNotNull() must be statically imported:
import static com.google.common.base.Preconditions.checkNotNull;
protected void dispatch(Message message, CommandContext context) {
checkNotNull(message);
checkNotNull(context);
...
}If a method returns a single object, it should never return null. Use Optional if the method can return nothing.
If a method returns a collection, it should never return null. Instead, it should return an empty immutable collection.
Suppress unchecked warnings via standardized @SuppressWarnings annotation only instead of IntelliJ IDEA-specific //noinspection suppression style. We want to keep code compliant with any tool, not just with IntelliJ IDEA.
Please do. Framework users and developers need to know the reason why a warning was suppressed.