Fudge
06/21/2019, 7:40 PMclass User(val name: String,val email:String)
They do
class User{
var name : String
var email: String
}
fun user(init: User.() -> Unit) = User.apply{init()}
What are the benefits of this?thana
06/24/2019, 7:53 AMclass SomeClass{
companion object{
fun from(someOther: SomeOther): SomeClass {
// create an instance from someOther
}
}
}
Now, if SomeClass
can be initialized with a builder the from
method can be re-written like
fun from(someOther: SomeOther) = SomeClass {
}
Here i can do really more than just creating an instance as i can use some conversion logic which is more complex than just passing some references
which might be more pleasant for some programmers' eyes to be done in an expression-style block than just a normal block 😉Fudge
06/24/2019, 12:20 PMthana
06/26/2019, 2:26 PM