gpt4 book ai didi

java - 带有 Kotlin 单元测试的 TestContainers PostgreSQLContainer : "Not enough information to infer type variable SELF"

转载 作者:行者123 更新时间:2023-12-01 11:29:47 25 4
gpt4 key购买 nike

我正在尝试使用 PostgreSQLContainer来自 测试容器 ( https://github.com/testcontainers/testcontainers-java + https://www.testcontainers.org/ ) 以对我的 JPA 存储库进行单元测试。
我这样声明我的容器:

private val postgresqlContainer = PostgreSQLContainer("postgres:12-alpine")
但是,我遇到了以下错误, 来自 Intellij IDE :

Not enough information to infer type variable SELF


我尝试启动服务时的完整错误是:

Error:(26, 43) Kotlin: Type inference failed: Not enough informationto infer parameter SELF in constructor PostgreSQLContainer<SELF :PostgreSQLContainer<SELF!>!>(p0: String!) Please specify itexplicitly.

最佳答案

这个技巧也有效

private val postgresqlContainer = PostgreSQLContainer<Nothing>().apply {
withDatabaseName("x")
withUsername("y")
withPassword("z")
}

关于java - 带有 Kotlin 单元测试的 TestContainers PostgreSQLContainer : "Not enough information to infer type variable SELF",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59007414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com