스칼라 if문

Volc·2023년 4월 13일
0

Scala

목록 보기
8/9

스칼라 if문

if (2 + 2 == 5) {
	println("Hello from 1984.")
} else if (2 + 2 == 3) {
	println("Hello from Remedial Math class?")
} else {
	println("Hello from a non-Orwellian future.")
}
  • java와 별 다를게 없어 보인다.
val configFile = new java.io.File("somefile.txt")

val configFilePath = if (configFile.exists()) {
	configFile.getAbsolutePath()
} else {
	configFile.createNewFile()
   	configFile.getAbsolutePath()
}
  • 스칼라는 문장이 값을 결과로 돌려주는 식이다.
  • if 식의 결과 값을 다른 변수에 저장할 수 있다.
  • configFilePath는 설정 파일이 존재하지 않는 경우를 내부에서 처리하고 절대 경로를 돌려주는 if문이다.
  • 3항 조건식은 중복 기능이므로 지원하지 않는다.
profile
미래를 생각하는 개발자

0개의 댓글