Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.39 KB | None | 0 0
  1. fun printProduct(arg1: String, arg2: String) {
  2.     val x = parseInt(arg1)
  3.     val y = parseInt(arg2)
  4.  
  5.     // Using `x * y` yields error because they may hold nulls.
  6.     if (x != null && y != null) {
  7.         // x and y are automatically cast to non-nullable after null check
  8.         println(x * y)
  9.     }
  10.     else {
  11.         println("either '$arg1' or '$arg2' is not a number")
  12.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement