scala基本数据类型学习

Scala数值与字符串字面量解析
本文深入探讨Scala中不同类型的数值字面量和字符串字面量的使用规则,包括整数、浮点数、字符及字符串的表示方法,特别关注了八进制数、长整型、双精度浮点数、Unicode字符以及原始字符串的语法细节。

  Scala does not support octal literals; integer literals that start with a 0, such as 031, do not compile.

  If an integer literal ends in an L or l, it is a Long; otherwise it is an Int.

  If a floating-point literal ends in an F or f, it is a Float; otherwise it is a Double. Optionally, a Double floating-point literal can end in D or d.

  Character literals are composed of any Unicode character between single quotes.

  In addition to providing an explicit character between the single quotes, you can identify a character using its Unicode code point. To do so, write \u followed by

four hex digits with the code point, like this:

  scala> val d = '\u0041'

  d: Char = A

  scala> val f = '\u0044'

  f: Char = D  

  This identifier is treated as identical to BAD, the result of expanding the two Unicode characters in the code above. In general, it is a bad idea to name

identifiers like this because it is hard to read. Rather, this syntax is intended to allow Scala source files that include non-ASCII Unicode characters to

be represented in ASCII.

  A string literal is composed of characters surrounded by double quotes.

  You start and end a raw string with three double quotation marks in a row ("""). The interior of a raw string may contain any characters whatsoever, including

newlines, quotation marks, and special characters, except of course three quotes in a row.

转载于:https://www.cnblogs.com/25th-engineer/p/11255876.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值