SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top