Orhan Tozan
04/04/2022, 12:09 PMcontext(Foo)
fun bar() {
...
}
and
fun Foo.bar() {
...
}
?
If not, will the 2nd way of writing be eventually deprecated?wasyl
04/04/2022, 12:18 PMthis
receiver within the block, and I don’t recall that the functions with receivers would be deprecatedwasyl
04/04/2022, 12:19 PMthis
behavior and an explicit suggestion to not use context receivers and functions with receivers interchangeably. But I don’t see an explicit comparison between the twowasyl
04/04/2022, 12:20 PMOrhan Tozan
04/04/2022, 12:21 PMwasyl
04/04/2022, 12:22 PMwasyl
04/04/2022, 12:22 PMwasyl
04/04/2022, 12:23 PMEven though both declarations are similar in many aspects, and their bodies look similar, the declaration ofis explicit about the intent to perform an action on thefun User.updateNow()
object.User
dmitriy.novozhilov
04/04/2022, 12:24 PMfun Foo.bar_1() {}
context(Foo)
fun bar_2() {}
fun test(foo: Foo) {
foo.bar_1() // ok
foo.bar_2() // error
with (foo) {
bar_1() // ok
bar_2() // ok
}
}
Orhan Tozan
04/04/2022, 12:25 PM