Kotlin: Expected type does not accept nulls in Java, but the value may be null in Kotlin
around a
MapSqlParameterSource("key", null)
- but the value can be null, as far as I can tell.
n
nfrankel
05/11/2018, 9:54 PM
you might be able to tell
but it seems the compiler cannot
perhaps you might have missed
@NotNull
annotations?
t
todd.ginsberg
05/12/2018, 1:21 AM
I ran into this same thing. It appears that
MapSqlParameterSource
doesn't have its
@Nullable
annotation set properly. But if you think about it, the reason that class exists is because there's no elegant way to express Maps in Java. But in Kotlin we have
mapOf("key" to null)
, which works as an argument to
NamedParameterJdbcTemplate
(assuming that's where you are using this).
m
Michael
05/14/2018, 1:50 PM
Ahh, so I could build the map first, then construct the
MapSqlParameterSource
from it, rather than using the
addValue
on the MSPS. That makes sense!
Michael
05/14/2018, 1:51 PM
(I’m actually using Spring Batch, not the template directly, so it I have to provide a