Skip to content

[Tour] Case Classes example error #2210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
krisweiss opened this issue Oct 26, 2021 · 2 comments
Closed

[Tour] Case Classes example error #2210

krisweiss opened this issue Oct 26, 2021 · 2 comments

Comments

@krisweiss
Copy link
Contributor

krisweiss commented Oct 26, 2021

There seems to be an error in the Tour of Scala, Basics, Case Classes example.

case class Point(x: Int, y: Int)

val point = Point(1, 2)
val anotherPoint = Point(1, 2)
val yetAnotherPoint = Point(2, 2)

if (point == anotherPoint) {
  println(point + " and " + anotherPoint + " are the same.")
} else {
  println(point + " and " + anotherPoint + " are different.")
}

if (point == yetAnotherPoint) {
  println(point + " and " + yetAnotherPoint + " are the same.")
} else {
  println(point + " and " + yetAnotherPoint + " are different.")
}

Running the code in https://scastie.scala-lang.org/ throws: value + is not a member of Playground.Point, but could be made available as an extension method.

Using a String type as the first argument seems resolves the issue:
println(point.toString + " and " + anotherPoint + " are the same.")
or
println("" + point + " and " + anotherPoint + " are the same.")

@SethTisue
Copy link
Member

I would recommend this be resolved by using a string interpolator (s"...") instead

@Philippus
Copy link
Member

fixed in #2211

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants