Type Inference‘s Best Practice
Programming Best Practices
1 min readDec 9, 2018
When to have type inference?
Better not annotate the type of a private field or a local variable as their type will usually be immediately evident in their value.
When to avoid type inference?
Better to display the type where the assigned value has a complex or non-obvious form.
All public methods should have explicit type annotations — without an explicit type, a change to the internals of a method or val could alter the public API of the class without warning, potentially breaking client code.