Kotlin - Operators and Expressions
Given this Kotlin class:
What is the result of this expression?
class Vector(val x: Int, val y: Int) {
operator fun plus(other: Vector) = Vector(x + other.x, y + other.y)
operator fun times(scalar: Int) = Vector(x * scalar, y * scalar)
}What is the result of this expression?
val v1 = Vector(2, 3)
val v2 = Vector(1, 1)
val result = (v1 + v2) * 2
println("(${result.x}, ${result.y})")