Guest User

Untitled

a guest
Jan 22nd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. private fun smartCasting(someObject: Any?) { //Any is the root class of all Kotlin objects
  2. if (someObject is String) {
  3. println("SomeObject is a String of value \"$someObject\" ")
  4. } else if (someObject is Int) {
  5. println("SomeObject is an Int of $someObject")
  6. println(someObject + 4)
  7. } else if (someObject is Employee) {
  8. println("SomeObject is an Employee named ${someObject.name}")
  9. } else {
  10. println("we\`re not sure what it is")
  11. }
  12. //the above structure can be converted to `when`. This is covered in Part 4.
  13. }
Add Comment
Please, Sign In to add comment