Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Variables and parameters should not be gratuitously decorated with the final keyword. This is an out-dated convention from Java 1.1 era. The only time this is required is when the parameter is used as part of an anonymous class closure defines within the method. Otherwise, let the Java compiler/optimizer to its work. The final keyword  keyword should also be used to on class declarations to make objects of the class immutable.

On a related note, even though method parameters are not decorated with final, they should still be treated as final; it is considered bad coding practice to modify a parameter within the method. The same behavior can always be achieved with local variables.

Code Block
public void badExample(SomeType type, SomeValue value) {
    if (value == null) {
        value = SomeValue.DEFAULT_VALUE;
    }
    ...
 
 
public void goodExample(SomeType type, SomeValue value) {
    SomeValue v = value != null ? value : SomeValue.DEFAULT_VALUE;
    ...

 

Naming

  • JSON fields should be in camel case:

    Code Block
    {
        "aliasIp": "10.1.2.3"
    }

    and not "alias_ip".

...