dirk.dittert
12/24/2024, 2:09 PMurl
):
class Example(private val url: String = "jdbc:h2:mem:") {
val dataSource: DataSource = JdbcDataSource().apply { setUrl(url) }
}
The error message is:
Overload resolution ambiguity between candidates:
var url: String!
var url: String!
The reason for that failure seems to be that the H2 JdbcDataSource
class has a private field url
. Is there a way to tell the compiler that url
should actually reference the value from Example
?Daniel Pitts
12/24/2024, 2:29 PMthis@Example.url
Daniel Pitts
12/24/2024, 2:32 PMclass Example(private val url: String = "jdbc:h2:mem:") {
val dataSource: DataSource = JdbcDataSource().also { it.setUrl(url) }
}
Daniel Pitts
12/24/2024, 2:32 PMapply
to also
)Daniel Pitts
12/24/2024, 2:33 PMclass Example(private val url: String = "jdbc:h2:mem:") {
val dataSource: DataSource = JdbcDataSource()
init {
dataSource.url = url
}
}
dirk.dittert
12/24/2024, 2:33 PMurl
in JdbcDataSource
is private)Daniel Pitts
12/24/2024, 2:34 PMdirk.dittert
12/24/2024, 2:35 PMgetURL()
method in the Java class. Knowing that, it makes a lot more sense.dirk.dittert
12/24/2024, 2:36 PMDaniel Pitts
12/24/2024, 2:36 PM