我的 Gradle 构建中有一个通用任务,它复制一些配置文件以包含在构建中,但编译或其他任何操作都不需要这些文件(它们在运行时使用)。基本上:
val copyConfiguration by tasks.registering(Copy::class) {
from("${projectDir}/configuration")
into("${buildDir}/")
}
Run Code Online (Sandbox Code Playgroud)
然而,这会导致所有其他任务中出现问题,因为我现在收到有关任务如何使用此输出而不声明显式或隐式依赖项的 Gradle 警告
Execution optimizations have been disabled for task ':jacocoTestCoverageVerification' to ensure correctness due to the following reasons:
- Gradle detected a problem with the following location: '...'. Reason: Task ':jacocoTestCoverageVerification' uses this output of task ':copyConfiguration' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.4.1/userguide/validation_problems.html#implicit_dependency for more details about …Run Code Online (Sandbox Code Playgroud) 仅供参考:我目前正在使用 Mockk-1.12.4 和 Kotlin-1.6
我有一个返回类型 T 的对象的扩展方法:
fun <T> Entity.selectReferenceAsSingleObject(referenceName: String): T {
return this.selectReferencesByName(referenceName).single().asObjet() as T
}
Run Code Online (Sandbox Code Playgroud)
它被定义为 Extentions.kt 文件中的顶级函数(因此不是一个类)。我想通过使用mockkStatic 用 MockK 来模拟这个
mockkStatic(Entity::selectReferenceAsOptionalSingleObject)
Run Code Online (Sandbox Code Playgroud)
但是我收到错误:
Not enough information to infer type variable T
Run Code Online (Sandbox Code Playgroud)
因为它无法确定我应该嘲笑什么类型。我尝试在很多地方添加类型参数
mockkStatic<KFunction<MyType>>(Entity::selectReferenceAsSingleObject)
mockkStatic<MyType>(Entity::selectReferenceAsSingleObject)
mockkStatic(Entity<KFunction<MyType>>::selectReferenceAsSingleObject)
mockkStatic(Entity<MyType>::selectReferenceAsSingleObject)
mockkStatic(Entity::<KFunction<MyType>>selectReferenceAsSingleObject)
mockkStatic(Entity::<MyType>selectReferenceAsSingleObject)
mockkStatic(Entity::selectReferenceAsSingleObject<KFunction<MyType>>)
mockkStatic(Entity::selectReferenceAsSingleObject<MyType>)
mockkStatic(Entity::selectReferenceAsSingleObject as KFunction<MyType>)
mockkStatic(Entity::selectReferenceAsSingleObject as MyType)
Run Code Online (Sandbox Code Playgroud)
但没有任何作用,它要么告诉我同样的错误,要么告诉我那里不允许类型参数。我不确定我需要做什么来修复我的语法,因为 IntelliJ 没有给我任何提示,所以我感觉有点卡住了。任何帮助,将不胜感激。
所以我想知道一种在Java中切换有效类型的简单方法,如下所示:
(我知道这不能编译,但我想要这个功能)
public void put(Object obj) {
if (obj instanceof Integer) {
} else if (obj instanceof String) {
} else if (obj instanceof Boolean) {
} else if (obj instanceof List<String>) {
} else if (obj instanceof Map<String, String>) {
}
}
Run Code Online (Sandbox Code Playgroud)