Skip to content

Instantly share code, notes, and snippets.

@sidd-kulk
Created June 21, 2019 11:31
Show Gist options
  • Save sidd-kulk/e196d13fbf6d1e814db8c93d40e8f653 to your computer and use it in GitHub Desktop.
Save sidd-kulk/e196d13fbf6d1e814db8c93d40e8f653 to your computer and use it in GitHub Desktop.
Kotlin code sample
fun main() {
val s = Square(2.0)
println(s.area()) // Prints 4.0, duh!
println(s - Square(3.0)) // Prints -5.0, Sweet!
}
data class Square (val side: Double) {
operator fun minus(other: Square): Double {
return this.area() - other.area()
}
fun area(): Double {
return side * side
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment