- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在完成 Kotlin Koans 的 Comparison练习并想知道为什么 compareTo()
是被重写的函数,但 compare()
是正在使用的函数。
这两个函数有何关联?
data class MyDate(val year: Int, val month: Int, val dayOfMonth: Int) : Comparable<MyDate> {
override fun compareTo(otherDate: MyDate): Int = when {
year != otherDate.year -> year - otherDate.year
month != otherDate.month -> month - otherDate.month
else -> dayOfMonth - otherDate.dayOfMonth
}
}
fun compare(date1: MyDate, date2: MyDate) = date1 < date2
最佳答案
compare()
函数那里只是一个占位符显示“如何使用compareTo()
”,没有实际意义。您可以根据需要将其更改为其他名称。
How do the two functions relate here?
随机命名的函数compare()
来电 MyDate
的compareTo()
带有比较器符号 <
的函数 。
关于 Kotlin 公案 : Operator overloading,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54955015/
我最近尝试使用这个工具来提高我的 Rails 技能: http://github.com/edgecase/ruby_koans 但我无法通过一些测试。此外,我不确定我是否正确地做了一些事情,因为目标
我正在完成 Kotlin Koans 的 Comparison练习并想知道为什么 compareTo() 是被重写的函数,但 compare() 是正在使用的函数。 这两个函数有何关联? data c
我正在解决 the python koans .直到 34 号我才遇到任何真正的问题。 问题是: Project: Create a Proxy Class In this assignment, c
在 about_symbols.rb Ruby Koan (https://github.com/edgecase/ruby_koans) 中,我有以下代码: RubyConstant = "
我是 Clojure 新手,所以我一直在浏览 Clojure Koans最后几天。事情进展得相当顺利,直到 section on sequence comprehensions 。我在这部分遇到困难。
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
我是一名优秀的程序员,十分优秀!