user1078671
user1078671

Reputation:

Omitting the return type in abstract method, but not in abstract field

For example i have the following trait:

trait Some {
  def method // i can omit the return type
  val field: Some  // i can't 
}

If i omit the type of an abstract field it will raise a compile error, but not in case of a method?

Upvotes: 1

Views: 64

Answers (1)

4lex1v
4lex1v

Reputation: 21557

It's drop-dead simple. If you omit the return type of an abstract method, then Scala compiler will infer it as a Unit (after typer phase):

abstract trait Some extends scala.AnyRef {
  def method: Unit;
  <stable> <accessor> def field: String
}

Upvotes: 2

Related Questions