Skip to content

Instantly share code, notes, and snippets.

@sweeneyapps
Created August 22, 2021 00:36
Show Gist options
  • Save sweeneyapps/7e30aa364f39fc25635151a30efe6ce3 to your computer and use it in GitHub Desktop.
Save sweeneyapps/7e30aa364f39fc25635151a30efe6ce3 to your computer and use it in GitHub Desktop.
package my.demo
import kotlin.text.*
fun main(args: Array<String>) {
for (arg in args) {
println(arg)
}
data class User(val name: String, val age: Int) {
override fun equals(other: Any?): Boolean {
return other is User && other.age == this.age
}
}
val user = User("John", 30)
val user2 = User("John", 30)
val user3 = User("John", 40)
println(user == user2)
println(user == user3)
println(user)
println(user.hashCode())
println(user2.hashCode())
println(user3.hashCode())
println(user.hashCode() == user2.hashCode())
println(user == user.copy())
println(user == user.copy(age = 40))
val copyofwhat = user.copy(age = 100)
println(copyofwhat.age)
println(user.component1())
println(user.component2())
// create a function that print a user (Github Copilot)
fun printUser(user: User) {
println("${user.name} is ${user.age} years old")
}
printUser(user)
}
// RESULT below in the terminal
/**************
➜ kotlin cat run
#!/usr/bin/env zsh
kotlinc $1 -include-runtime -d demo.jar && java -jar demo.jar $@
➜ kotlin ./run demo5.kt
demo5.kt
true
false
User(name=John, age=30)
71750739
71750739
71750749
true
true
false
100
John
30
John is 30 years old
➜ kotlin yaya!!
************/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment