Scala-data types and custom functions

type of data

type of data description
Byte 8-bit signed integer
Short 16-bit signed integer
Int 32-bit signed integer
Long 64-bit signed integer
Float 32-bit single precision floating point
Double 64-bit single-precision floating-point number
Char 16-bit unsigned character
String Character sequence
Boolean true or false
Unit Means no value, equivalent to void in other languages, var s = ()
Null null or null reference
Nothing Nothing produced an exception during execution, def s = throw new Exception ("")
Any Any is a superclass of all other classes
AnyRef The AnyRef class is the base class of all reference classes in Scala

Declaration of variables and constants

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

String concatenation

s"Hello ${s}"

Custom function

# 函数定义的时候,可以不写返回值,scala支持类型推导
def 函数名称(参数名称 : 参数类型) : 返回值类型 = {
	函数的实现
}
Published 131 original articles · won 12 · 60,000 views +

Guess you like

Origin blog.csdn.net/JavaDestiny/article/details/91634902