Not a beginner but i found something maybe strange. The receive parameter T is marked unused here, but it is required
Posted in #kotlinforbeginners
c
Casey Brooks
12/15/2022, 7:24 PM
The receiver here is required because you have it defined as a property. You cannot explicitly provide type parameters to a property like you can when calling a function, so the only way to pass a type parameter to a property extension is via its Receiver. So even though the Receiver object itself is not used in the function, it is still required since the Receiver carries its T type parameter with it into the extension function.
The warning, though, might be a false positive for you. It seems to detect it as necessary in my IDE. I’m not sure why it’s not resolving correctly for you, but you can add
@Suppress("UnusedReceiverParameter")
to make the warning go away, at least
i
Ido Flax
12/15/2022, 8:22 PM
So can we say it’s an issue with intellij?
j
Jacob
12/15/2022, 10:02 PM
It looks like a good warning to me. The body of your function uses no properties and calls no functions on the receiver
Jacob
12/15/2022, 10:08 PM
lose the
T.
and instead of calling
myObject.logger()
call
logger<MyObject>()
The latter function has less in its scope since it can't access any instance properties and functions. Keeping the amount of data in function scopes as small as possible is a good practice
i
Ido Flax
12/16/2022, 9:44 AM
I don’t know why i went so complicated about it when i actually just wanted to achieve this: