How do I prevent these two declarations from havin...
# announcements
j
How do I prevent these two declarations from having the same JVM type signature?
Copy code
class NamedDomainObjectContainerScope<T : Any>(
    private val container: NamedDomainObjectContainer<T>) : NamedDomainObjectContainer<T> by container {

    operator fun String.invoke(configuration: T.() -> Unit): T =
        this().apply(configuration)

    /**
     * @see [NamedDomainObjectContainer.maybeCreate]
     */
    inline
    operator fun <reified U : T> String.invoke(configuration: U.() -> Unit): U =
        this(U::class).apply(configuration)
}
Use case: I want to be able to do this:
Copy code
container { // `this` is type `NamedDomainObjectContainerScope<Task>`
    "allice" { /* Type Task in this scope*/ }
    "bob"<ExtendedTaskType> { /* Type ExtendedTaskType in this scope*/ }
}
My more general problem is that I'm trying to add
reified
overloads for all of these methods in the Gradle Kotlin DSL: https://github.com/gradle/kotlin-dsl/blob/6a3c51a65e8423aa33432b816996360cd32e7906/provider/src/main/kotlin/org/gradle/kotlin/dsl/NamedDomainObjectContainerExtensions.kt
a
@jlleitschuh what problem are you facing? declarations clash?
j
Yea. And if I just have the reified version then the invoke the compiler requires an explicit generic at the call site which I don't want.
a
j
Oooh. Clever. Hopefully it doesn't get slapped down when it comes to the code review. I'll give that a shot though.
This solved the problem nicely!!! Thanks!!!
­čĹŹ 2