Hey, I have no idea where to post this, but I am a...
# getting-started
i
Hey, I have no idea where to post this, but I am at a complete loss and cannot find anything online. The issue is with log4j-2. There's a class for structured logging called
MapMessage
and it is possible to use from Java, but not from Kotlin. So this java code works just fine and it is able to infer the type params of MapMessage (which are
MapMessage<M extends MapMessage<M, V>, V>
, so there is a self capture there)
Copy code
Logger l = LogManager.getLogger();
 l.info(new MapMessage<>(Map.of("r", 1)));
While Kotlin code like this fails with
Cannot infer type for this parameter. Please specify it explicitly.
Which is impossible to do.
Copy code
val logger = LogManager.getLogger()
 <http://logger.info|logger.info>(MapMessage(mapOf("key" to "value")))
Any help would be appreciated. I can use
StringMapMessage
as that binds the first parameter to be itself, but that is limiting.
y
You could just use
MapMesaage<*, _>(mapOf(...))
i
It is not allowed to use * there
e
hack but
Copy code
MapMessage<Nothing, _>(mapOf(...))
would work
i
It crashed the compiler
e
hmm. works in a simple example here blob shrug
i
I'm on 2.0.20
e
you could create a less tricky subtype
Copy code
class KotlinMapMessage<V>(map: Map<String, V>) : MapMessage<KotlinMapMessage<V>, V>(map)
and use that instead
ditto…
i
I think it crashes something in the gradle pipeline for me, huh
Also intellij
Yeah, I guess some wrapper like that should work
Or adapter, or whatever
It's just interesting if that is expected behaviour of Kotlin type inference?
I understand that the algorithms are not identical, but it's the first time in years I see something like this
e
crashing isn't expected behavior, but it being stricter about
M
might be, I'm not sure
i
Well, crashing sure is not 😃
Thanks for helping btw