Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. //show type is erased in runtime
  2. // show reified
  3.  
  4. fun <T> checkTypeAtRuntime(item: Any){
  5. println("${item is T}")
  6. }
  7.  
  8. fun main(){
  9. val names: MutableList<String> = mutableListOf("John", "Sarah", "Mark")
  10. val ages: MutableList<Int> = mutableListOf(1,2,3)
  11.  
  12. checkTypeAtRuntime<String>("John")
  13. checkTypeAtRuntime<Int>("Sarah")
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement