Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun printProduct(arg1: String, arg2: String) {
- val x = parseInt(arg1)
- val y = parseInt(arg2)
- // Using `x * y` yields error because they may hold nulls.
- if (x != null && y != null) {
- // x and y are automatically cast to non-nullable after null check
- println(x * y)
- }
- else {
- println("either '$arg1' or '$arg2' is not a number")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement