Not a beginner but i found something maybe strange...
# intellij
i
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
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
So can we say it’s an issue with intellij?
j
It looks like a good warning to me. The body of your function uses no properties and calls no functions on the receiver
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
I don’t know why i went so complicated about it when i actually just wanted to achieve this:
b
I would suggest using a function instead...