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
Student.Builder() | |
.name("Alex") | |
.standard(10) | |
.rollNumber(720) | |
.build() | |
VS | |
Student.build { | |
name = "Alex" |
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
class Student( | |
val name: String?, | |
val standard: Int, | |
val rollNumber: Int | |
) { | |
private constructor(builder: Builder) : this(builder.name, builder.standard, builder.rollNumber) | |
class Builder { | |
var name: String? = null |
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
class Student( | |
val name: String?, | |
val standard: Int, | |
val rollNumber: Int | |
) { | |
private constructor(builder: Builder) : this(builder.name, builder.standard, builder.rollNumber) | |
companion object { | |
inline fun student(block: Student.Builder.() -> Unit) = Student.Builder().apply(block).build() |