Hi, in this piece of code, I'm mocking a JDBC `Res...
# mockk
k
Hi, in this piece of code, I'm mocking a JDBC
ResultSet
, and therefore its
getLong()
method returns a JVM platform type (i.e. it could be
Long
or
Long?
):
Copy code
val id: Long? = <...>
every { resultSet.getLong("id") } returns id
Unfortunately, this results in the error message "Type mismatch: inferred type is Long? but Long was expected." Is this a bug, a known limitation, or something I'm doing wrong? I can work around it like this:
Copy code
every { resultSet.getLong("id") as Long? } returns id
but then IntelliJ IDEA warns me that
as Long?
is unnecessary.
s
I think the problem may actually be the opposite of what you describe.
getLong
returns a primitive
long
, so it can never be null. Your id is defined as
Long?
, which is nullable, so it can't be used as a return value for
getLong
.
👍 1
k
Indeed, you're right, Sam. My mistake. Thanks.