刚学习如何定义日期范围类型
val wholeYear2017 = Date(2017,1,1)..Date(2017,12,31)
所以我创建了以下类型
class DateRange<Date: Comparable<Date>>(override val start: Date, override val endInclusive: Date)
: ClosedRange<Date>
class Date (val year: Int, val month: Int, val day: Int) {
operator fun compareTo(other: Date): Int {
if (this.year > other.year) return 1
if (this.year < other.year) return -1
if (this.month > other.month) return 1
if (this.month < other.month) return -1
if (this.day > other.day) return 1
if (this.day < other.day) return -1
return 0
}
operator fun rangeTo(that: Date): DateRange = DateRange(this, that)
}
但是我遇到了编译错误
One type of argument expected for class DateRange<Date: Comparable<Date>> : ClosedRange<Date>
我错过了什么?我做得对吗?