Skip to content

Instantly share code, notes, and snippets.

@automationhacks
Created July 3, 2019 16:50
Show Gist options
  • Save automationhacks/5c3f28d09cd2cfc229863f39534d3c66 to your computer and use it in GitHub Desktop.
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
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")
}
@mcweba
Copy link

mcweba commented Jul 17, 2019

Small bug in the println statement. $anotherResult should be used I guess

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment