Kotlin type inference failed but I cannot specify a Kotlin class type?

Hello.

Iam facing some very basic problem and wondering if someone could help me to solve it (that never faced in java before) and might be due to my lack of knowledge in Kotlin.

I am currently trying to read a YML file. So Im doing it in this way:

private val factory = YamlConfigurationFactory(LinkedHashMap::class.java, validator, objectMapper, "dw")

Best on Dropwizard guide for configurations.

https://www.dropwizard.io/1.3.12/docs/manual/testing.html

So later in my function, I do this"

 val yml = File(Paths.get("config.yml").toUri())
 var keyValues =  factory.build(yml)

When using my debugger I can see there is a Map with key->values, just as it should be.

now when I do keyValues.get(“my-key”)

type inference failed. the value of the type parameter k should be mentioned in input types

Tried this but no luck

var keyValues =  LinkedHashMap<String, Any>()
keyValues =  factory.build(yml)

The YamlConfigurationFactory requires a class to map to, but I dont know if there is a more direct way to specify a Kotlin class than with the current solution +.kotlin, like

LinkedHashMap::class.java.kotlin

Here it also throws an error.

Ideas?

Which version of the Kotlin plugin are you using? There are some known similar problems with the new inference algorithm enabled by default in 1.3.40 plugin in IDE, but they were mostly fixed in 1.3.41: https://youtrack.jetbrains.com/issues/KT?q="should%20be%20mentioned%20in%20input%20types"

If you are using 1.3.41, try to disable the new inference in “Preferences | Build, Execution, Deployment | Compiler | Kotlin Compiler”. Does it work now?