
‘==’ : 주소 + 값 같은가
‘.equals() : 값 같은가
‘===’ : 주소 + 값 같은가
‘==’ : 값 같은가
var money1 = Money(1000L);
var money2 = Money(3000L);
println(money1 + money2);
//Money(amount=4000) 자동으로 toString이 들어가있다.If 문 자바랑 동일
fun validateScoreIsNotNegative(score: Int) {
    if (score < 0) {
        throw IllegalArgumentException("${score}는 0 보다 작을수 없습니다.")
    }
}
fun getPassOrFail(score: Int): String {
    if (score >= 50) {
        return "P"
    } else {
        return "F"
    }
}하지만 Java 에서는 if-else는 Statement 이지만, Kotlin에서는 Expression 이다.

int score = 30 + 40; //70이라는 하나의 결가과 나온다. (Expression 이면서 statment)
fun getKotlinPassOrFail(score: Int): String {
    return if (score >= 50) {
        "P"
    } else {
        "F"
    }
}
즉 kotlin 에서는 if-else를 expression 으로 사용할 수 있기 때문에 3항 연산자가 없다.
fun getKotlinGetGrade(score: Int): String {
    return if (score >= 90) {
        "A"
    } else if (score >= 80) {
        "B"
    } else {
        "C"
    }
}switch
fun kotlinValidateScore(score: Int) {
    if (score !in 0..100) {
        throw IllegalArgumentException("score 범위는 0부터 100이 아닙니다.")
    }
}
fun kotlinValidateScore(score: Int) {
    if (score in 0..100) {
        throw IllegalArgumentException("score 범위는 0부터 100입니다.")
    }
}
//코틀린은 switch 가 사라짐 대신에 when을 사용
 fun getGradeWithSwitch(score: Int): String{
    return when (score/10){
        9 -> "A";
        8 -> "B";
        7 -> "C";
        6 -> "D";
        else -> "E"
    }
}
//범위
fun getGradeWithSwitch(score: Int): String{
    return when (score/10){
        in 80..90 -> "A";
        in 70..80 -> "B";
        in 60..70 -> "C";
        in 50..60 -> "D";
        else -> "E"
    }
}
//객체가 스트링이라면...  
fun startWithA(obj: Any):Boolean{
    return when(obj){
        is String -> obj.startsWith("A")
        else -> false
    }
}
fun judgeNumber(number: Int) {
    when (number) {
        1, 0, -1 -> println("어디서 많이 본 숫자 입니다.")
        else -> println("1,0,-1 이 아닙니다.")
    }
}
fun judgeNumber2(number: Int) {
    when {
        number == 0 -> println("주어진 숫자는 0입니다.")
        number % 2 == 0 -> println("주어진 숫자는 짝수입니다.")
        else -> println("주어진 숫자는 홀수입니다.")
    }
}
좋은 글 감사합니다. 자주 방문할게요 :)