Skip to content

Instantly share code, notes, and snippets.

@arsalankhan994
Last active February 6, 2022 16:03
Show Gist options
  • Save arsalankhan994/dfadc6ec325c012937c7dc64059b9071 to your computer and use it in GitHub Desktop.
Save arsalankhan994/dfadc6ec325c012937c7dc64059b9071 to your computer and use it in GitHub Desktop.
fun main() {
// Smart Casting
var studentWithRealObject: Any? = Student()
if (studentWithRealObject is Student) {
println("Student name: ${studentWithRealObject.name}")
println("Student age: ${studentWithRealObject.age}")
}
}
data class Student(
val name: String = "Erselan Khan",
val age: Int = 27
) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment