https://kotlinlang.org logo
#getting-started
Title
# getting-started
v

Vampire

11/04/2023, 1:08 AM
How do you trick the type checker if you just know better? For example in Gradle context if I do
Copy code
configurations.create("foo") {
    val runtimeAttributes = configurations.runtimeClasspath.get().attributes
    runtimeAttributes.keySet().forEach { key ->
        attributes.attribute(key, runtimeAttributes.getAttribute(key))
    }
}
I know that
key
and
runtimeAttributes.getAttribute(key)
are compatible, but the Kotlin compiler does not. The method is declared
attribute(Attribute<T> key, T value)
e

ephemient

11/04/2023, 1:14 AM
Copy code
.attribute(key as Attribute<Any>, runtimeAttributes.getAttribute(key))
unchecked cast would probably bypass it
v

Vampire

11/04/2023, 1:15 AM
Nope 😞
Oh, wait, Kotlin is happy now, just IntelliJ is still painting it red, thanks