Skip to content

Scala 3 book: Create integer and string variables redefines a immutable variable #3191

New issue

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

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

Already on GitHub? # to your account

Open
VivCh14 opened this issue May 13, 2025 · 1 comment

Comments

@VivCh14
Copy link

VivCh14 commented May 13, 2025

The example at create-integer-and-string-variables, for Scala uses immutable variable x to re-define it from Int to a String type. Solution would be to either use another variable say z or make the x variable of type var that will make it mutable.

val x = 1
val z = "Hi"
val y = """foo
           bar
           baz"""

or

var x = 1
var x = "Hi"
val y = """foo
           bar
           baz"""

@bishabosha
Copy link
Member

it was probably a mistake to reuse x so x, y, z makes sense

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants