Skip to content

Instantly share code, notes, and snippets.

@sliskiCode
Created October 25, 2016 08:43
Show Gist options
  • Save sliskiCode/b42a582ac4807ee005aaa5f1abf68b40 to your computer and use it in GitHub Desktop.
Save sliskiCode/b42a582ac4807ee005aaa5f1abf68b40 to your computer and use it in GitHub Desktop.
Builders in Kotlin. Gist 5
val withTitle: Boolean = true
// More concise
Person.create {
name { if (withTitle) "Mr. Peter" else "Peter" }
surname { "Slesarew" }
age { 28 }
}
// It does not even compile
Person(if (withTitle) name = "Mr. Peter" else name = "Peter",
surname = "Slesarew",
age = 28)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment