74 단어
1 분
Kotlin 커스텀 접근자
커스텀 접근자
class Rectangle(val height: Int, val width: Int) {
val isSquare: Boolean
get() {
height == width
}
}코틀린에서는 식으로 표현할 수 있다. 따라서 아래와 같은 코드로 작성할 수도 있다.
class Rectangle(val height: Int, val width: Int) {
val isSquare: Boolean
get() = height == width
}Kotlin 커스텀 접근자
https://realits.me/posts/kotlin-custom/