Skip to content

Redundant new and val keywords usage in the 'Operators' section of the Scala Tour #1443

@maseev

Description

@maseev

From the Operators:

case class Vec(val x: Double, val y: Double) {
  def +(that: Vec) = new Vec(this.x + that.x, this.y + that.y)
}

Since case classes do not require the val keyword for parameters of case class primary constructor and do not require the new keyword to create an instance of a case class, the example above could be simplified as follows:

case class Vec(x: Double, y: Double) {
  def +(that: Vec) = Vec(this.x + that.x, this.y + that.y)
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions