var a // 컴파일 되지 않음
var b = 10 // b는 Int로 선언됨
var c = null // 가능함
var d: Int = 10 // 자료형을 명시적으로 줄 수 있음
한번 자료형이 결정되면, 다른 자료형으로 변경 불가능함
var a = 10
a = "이건 안됨?" // 이거 안됨
null 보다는 None을 사용하기를 권장
var a = None
a = 10 // 이거 안됨
var b = null // Null 자료형으로 선언됨
b = 10 // 이거도 안됨
var c:Int = None // 이것도 안됨
var d:Int = null // 이건 됨!!!
d = 10 // 이것도 됨!!
null은 다른 자료형에 들어갈 수 있음 (그래서 None을 쓰라는것 같음)
기본 자료형과 참조 자료형
기본 자료형은 String을 제외하고 모두 AnyVal
참조 자료형은 AnyRef
Unit 은 void와 같음
기본 자료형은 모두 메모리에 바로 기록되는 value type
tyep을 이용한 자료형 별칭
type Name = String
type Person = (String, Int)
type FType = String => Int
val name: Name = "홍길동"
val person: Person = ("홍길동", 30)
val f: FType = text => text.toInt
변수 선언
기본 자료형과 참조 자료형
tyep을 이용한 자료형 별칭
위와 같이 자료형에 alias를 걸 수 있음