If I'm not mistaken, this should work.
# getting-started
c
If I'm not mistaken, this should work.
🚫 1
y
Add:
Copy code
context(logger: Logger) fun log() = logger.log()
p
Bit off topic; I’ve been programming Kotlin for 3 years now and never used this feature (context receivers). Is it kind of a niche feature? Or am I missing out on something good?
a
It's very new and still in development, so for now you should avoid using it unless you really need to But for creating contextual/complex DSLs that's very great
y
Experimenting with them is absolutely worth it.
c
I'm still not convinced by the bridge functions 😕
y
@CLOVIS I've found them helpful if a type has "too many things exposed" and thus would pollute the scope if brought in as a receiver. That type may still be valid as a normal receiver because it's difficult with normal receivers to have too many in scope (each receiver necessarily results in one extra level of indentation), but it's really easy with contexts
f
Isn't it getting deprecated in 2.3?
a
No Context Parameters and Context Receivers are a different thing
c
I understand that in the final version of the context parameters, this won't be an error, right? If not, I don't understand why they were created.
c
What is the variable
context
here?
a
You have to name the parameters, ex:
context(thing: String)
, then you'll be able to use it as
thing.something()
c
Sorry, I think I understand how it works. Since I'm used to using context receivers, I thought that "_:" was going to be the same as an Extension Function.
👍 1
Screenshot 2025-04-30 at 10.09.44.png