Skip to content

Instantly share code, notes, and snippets.

@AmandaRiu
Last active May 5, 2018 00:41
Show Gist options
  • Save AmandaRiu/b5aa359e1b2298e8aaffd016f138366b to your computer and use it in GitHub Desktop.
Save AmandaRiu/b5aa359e1b2298e8aaffd016f138366b to your computer and use it in GitHub Desktop.
Random kotlin tricks

Change generated getter/setter methods

Kotlin does something strange with boolean types. If you have a boolean called isCanceled, the setter will be setCanceled(boolean) and the getter will be isCanceled(). Override this naming convention:

var isCanceled = false
  @JvmName("setIsCanceled")
  get

Assign method to variable and pass as argument

val onUpdated = {
  doSomething()
  doSomethingElse()
}

// pass as an argument
showTheNextStep(onUpdated)

// fire method
onUpdated()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment