Scala-数据类型与自定义函数

数据类型

数据类型 描述
Byte 8位有符号整数
Short 16位有符号整数
Int 32位有符号整数
Long 64位有符号整数
Float 32位单精度浮点数
Double 64位单精度浮点数
Char 16位无符号字符
String 字符序列
Boolean true或false
Unit 表示无值,与其他语言的void等同,var s = ()
Null null或空引用
Nothing Nothing在执行过程中,产生了异常Exception,def s = throw new Exception("")
Any Any是所有其他类的超类
AnyRef AnyRef类是Scala里所有引用类(reference class)的基类

变量与常量的声明

# 变量声明
var s : String = ""
# 常量声明
val s : String = ""

字符串的拼接

s"Hello ${s}"

自定义函数

# 函数定义的时候,可以不写返回值,scala支持类型推导
def 函数名称(参数名称 : 参数类型) : 返回值类型 = {
	函数的实现
}
发布了131 篇原创文章 · 获赞 12 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/JavaDestiny/article/details/91634902