Explicit Function Parameter and Return Types

Always declare the parameter types and return types for functions/methods.

Do this:

BigDecimal getCost(BigDecimal number) { // ... }

Avoid this:

def round(number) { // ... }

Declaring the types explicitly not only provides type safety, but also allows the types to serve as a form of documentation, which makes the code easier to read and understand and makes it more re-usable by other team members.

Found an issue in documentation? Write to us.