我想输入:

        project.tasks<JmhTask> {
            ...
        }

代替
        project.tasks.withType(JmhTask::class.java) {
            ...
        }
tasksTaskContainer类型,扩展了interface DomainObjectCollection<T> extends Collection<T>DomainObjectCollection还定义::withType如下:
<S extends T> DomainObjectCollection<S> withType(Class<S> type, Action<? super S> configureAction);
我尝试执行以下操作(为简单起见,首先针对TaskContainer接收器):
    inline operator fun <reified S> TaskContainer.invoke(configureAction: Action<in S>?) =
            withType(S::class.java, configureAction)

不幸的是withType标记为红色:
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)

10-05 21:16