Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private fun smartCasting(someObject: Any?) { //Any is the root class of all Kotlin objects
- if (someObject is String) {
- println("SomeObject is a String of value \"$someObject\" ")
- } else if (someObject is Int) {
- println("SomeObject is an Int of $someObject")
- println(someObject + 4)
- } else if (someObject is Employee) {
- println("SomeObject is an Employee named ${someObject.name}")
- } else {
- println("we\`re not sure what it is")
- }
- //the above structure can be converted to `when`. This is covered in Part 4.
- }
Add Comment
Please, Sign In to add comment