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

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

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.

相关文章

共收录Twitter的14款开源软件,第1页Twitter的Emoji表情 Tw...
Java和Scala中关于==的区别Java:==比较两个变量本身的值,即...
本篇内容主要讲解“Scala怎么使用”,感兴趣的朋友不妨来看看...
这篇文章主要介绍“Scala是一种什么语言”,在日常操作中,相...
这篇文章主要介绍“Scala Trait怎么使用”,在日常操作中,相...
这篇文章主要介绍“Scala类型检查与模式匹配怎么使用”,在日...