Generics Kotlin泛型和类型变量
我想打:Generics Kotlin泛型和类型变量,generics,kotlin,type-variables,Generics,Kotlin,Type Variables,我想打: project.tasks<JmhTask> { ... } 任务属于TaskContainer类型,它扩展了接口DomainObjectCollection扩展了集合 DomainObjectCollection还定义了::withType,如下所示: 类型为类类型的DomainObjectCollection,操作这个怎么样 inline operator fun <reified S : Task>
project.tasks<JmhTask> {
...
}
任务属于TaskContainer类型,它扩展了接口DomainObjectCollection扩展了集合
DomainObjectCollection还定义了::withType,如下所示:
类型为类类型的DomainObjectCollection,操作这个怎么样
inline operator fun <reified S : Task> TaskContainer.invoke(configureAction: Action<in S>) =
withType(S::class.java, configureAction)
这个怎么样
inline operator fun <reified S : Task> TaskContainer.invoke(configureAction: Action<in S>) =
withType(S::class.java, configureAction)
有可能用DomainObjectCollection接收器来代替吗?我想是的。您是否尝试过用DomainObjectCollection替换TaskContainer?是否可以用DomainObjectCollection接收器替代它?我想是的。您是否尝试用DomainObjectCollection替换TaskContainer?
None of the following functions can be called with the arguments supplied.
withType(Class<TypeVariable(S)!>, (Closure<Any!>..Closure<*>)) where S = TypeVariable(S) for fun <S : Task!> withType(type: Class<S!>, configureClosure: (Closure<Any!>..Closure<*>)): DomainObjectCollection<S!> defined in org.gradle.api.tasks.TaskContainer
withType(Class<TypeVariable(S)!>, Action<in TypeVariable(S)!>) where S = TypeVariable(S) for fun <S : Task!> withType(type: Class<S!>, configureAction: Action<in S!>): DomainObjectCollection<S!> defined in org.gradle.api.tasks.TaskContainer
inline operator fun <reified S : Task> TaskContainer.invoke(configureAction: Action<in S>) =
withType(S::class.java, configureAction)