Skip to content

Instantly share code, notes, and snippets.

@adibfara
Last active September 5, 2018 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adibfara/2613991c39d8249eda09e7668f50a156 to your computer and use it in GitHub Desktop.
Save adibfara/2613991c39d8249eda09e7668f50a156 to your computer and use it in GitHub Desktop.
Kotlin contracts
/**
* @author Adib Faramarzi (adibfara@gmail.com)
*/
fun createOnce(runFunction: ()-> Unit) {
runFunction()
}
fun getKotlinVersion(): Float{
val kotlinVersion: Float
createOnce {
kotlinVersion = 1.3f
}
// The line below generates the error (and does not compile):
// Captured values initialization is forbidden due to possible reassignment
return kotlinVersion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment