Scala

Scala

Made by DeepSource

Parameterless method has return type - Unit SC-R1014

Style
Minor

Parameterless methods usually return a value and are part of the language. Having such methods have a return type of Unit can affect/hinder readability and defeats the purpose for which it was introduced as part of the syntax/language.

Bad Practice

// This method, judging by its name, suggests that it might return something as it is parameterless, when in reality
// it doesn't return anything!
def foo: Unit = {
  // body
}

Recommended

def foo(): Unit = {
  // body
}

A general way of using parameterless method is -

def name: String = {
  // body
}

println(user.name)