9 November 2018

Opinionated Java Coding.

Never write a method for which null is acceptable input.

Never write a method that returns a null. They should return an object. If failure is an option return an Optional. These methods should favor having only one return statement and if using Optional it should be used once in the return statement. Optional.flatMap, Optional.ofNullable and Optional.orElseGet provide the functionality to make this happen. this encourages smaller methods.

Almost always make classes and methods final. Immutability should be the norm not the exception.

Favor dependency inversion by constructors that take all input.

tags: java - java 8

Less Is More