Created
April 5, 2020 13:02
-
-
Save rajBopche/f9266b66cf97636bea45fe8b80df7e07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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