Created
July 3, 2019 16:50
-
-
Save automationhacks/5c3f28d09cd2cfc229863f39534d3c66 to your computer and use it in GitHub Desktop.
Result of If can be assigned to the variable and the last statement in conditional is automagically returned
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package _05_expressions | |
// Simple HTTP response class | |
class Response(val statusCode: Int) | |
fun main() { | |
// A sample response | |
val response = Response(200) | |
// In Kotlin, After lifting the assignment out of if else block | |
val anotherResult = | |
if (response.statusCode == 200) { | |
"Success" | |
} else { | |
"Failure" | |
} | |
println("API call results is : $result") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Small bug in the println statement. $anotherResult should be used I guess