2023-10-12から1日間の記事一覧

compareValuesByを使ってもっと簡単にComparableを実装する

data class CustomDate( val year: Int, val month: Int, val day: Int ) : Comparable<CustomDate> { override fun compareTo(other: CustomDate): Int { return compareValuesBy(this, other, CustomDate::year, CustomDate::month, CustomDate::day) } override fun t</customdate>…

Comparableを実装する

data class CustomDate( val year: Int, val month: Int, val day: Int ) : Comparable<CustomDate> { override fun compareTo(other: CustomDate): Int { if (year == other.year) { if (month == other.month) { return day - other.day } else { return month - other</customdate>…