gpt4 book ai didi

Scala 在同一行声明多个变量,且第一个字符为大写

转载 作者:行者123 更新时间:2023-12-01 17:37:21 28 4
gpt4 key购买 nike

我试图通过元组赋值来声明变量,例如:

val (hi, bye) = ("hi", "bye")

显然这很好。然而,当第一个字符为大写时,编译器会爆炸并提示这些变量尚未定义。

val (Hi, Bye) = ("hi", "bye")

为什么这不起作用?我运行的是 Scala 2.11。

顺便说一句,这有效(如预期):

val Hi = "hi"
val Bye = "bye"

最佳答案

来自here :

The tuple on the left-hand side is a pattern; names starting with capital letters are treated as constants when occurring inside a pattern. These constants must exist as values in the context. You find the exact semantics in the Scala spec under pattern matching.

关于Scala 在同一行声明多个变量,且第一个字符为大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27502999/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com