what would be the use case of apply here? (actuall...
# getting-started
e
what would be the use case of apply here? (actually curious)
d
Usually legacy "POJO" classes which require initialization like this:
Copy code
val thing = MyThing().apply {
    setFoo("foo")
    setBar("bar")
}
s
maybe the question is more what’s the benefit of doing that rather than just using the setters
Copy code
val thing = MyThing
thing.foo = "foo"
thing.bar = "bar"
like I suppose it’s a bit more concise, you’re not typing
thing.
over and over
d
That, plus it can be used in a place where you need an expression, e.g.
return
.
e
i understand in the case of object initialization (it makes builders quite easy for example)
s
ah the return thing is kind of nice, that’s a good point
e
I just forgot that double brace init is valid for any object in java (android world here, old java)