Skip to content

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

Description

@VivCh14

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"""

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions