I have a java class without a constructor that I w...
# getting-started
k
I have a java class without a constructor that I want to initialize with a value, is there a shortcut to do this in kotlin or do I have to initialize and use the setter?
d
You can use `also`:
Copy code
val instance = MyJavaClass().also {
   it.setValue("foo")
}
👍 1
k
What about apply with foo = bar?
d
Also works,
apply
has the same effect, just that you can use
this
inside the lambda
👍 1
k
Thanks!