Skip to content

Instantly share code, notes, and snippets.

@rajBopche
Created April 5, 2020 13:02
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 rajBopche/f9266b66cf97636bea45fe8b80df7e07 to your computer and use it in GitHub Desktop.
Save rajBopche/f9266b66cf97636bea45fe8b80df7e07 to your computer and use it in GitHub Desktop.
package builder
class User private constructor(
val firstName: String,
val lastName: String,
val mobileNumber: String,
val age: Int
) {
data class Builder(
private var firstName: String = "",
private var lastName: String = "",
private var mobileNumber: String = "",
private var age: Int = -1
) {
fun firstName(firstName: String) = apply { this.firstName = firstName }
fun lastName(lastName: String) = apply { this.lastName = lastName }
fun mobileNumber(mobileNumber: String) = apply { this.mobileNumber = mobileNumber }
fun age(age: Int) = apply { this.age = age }
fun build() = User(firstName, lastName, mobileNumber, age)]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment