日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Kotlin operator方法的重載

作者:安果移不動 更新時間: 2022-05-12 編程語言

重寫加法讓他支持加法

data class Coordinate2(var x: Int, var y: Int) {
    operator fun plus(c2: Coordinate2) = Coordinate2(x + c2.x, y + c2.y)

}

fun main() {
    val c1 = Coordinate2(10, 20)
    val c2 = Coordinate2(10, 20)
    println(c1 + c2)
}

其他的一些重載寫法

原文鏈接:https://blog.csdn.net/mp624183768/article/details/123894791

欄目分類
最近更新