Is there an annotation or other way to hint to Kotlin compiler to force my field to use java.lang.Integer, WITHOUT making it nullable?
I had posted months back about woes with using mybatis and it complaining about primitive ints and us having to do some whacky constructor hacks.
data class InventoryPosition(
var locationNumber: Int = 0,
var itemNumber: Long = 0,
var state: String = "",
var quantity: Double = 0.0
) {
fun mybatis() = (locationNumber.toString() == itemNumber.toString() && state == quantity.toString())
}
Essentially above is our less hacky way of forcing the Int fields to java.lang.Integer instead of int. We don’t want to make them nullable so that we dont have to pass that null checking around everywhere.
It would be nice if there were an acceptable way to do some kind of
@JvmBoxed val itemNumber: Int
Any other suggestions or ideas?
For reference, below is the more hacky way we had to do it previously
data class InventoryPosition(
val locationNumber: Int,
val itemNumber: Long,
val state: String,
val quantity: Double
) {
constructor(
locationNumber: java.lang.Integer,
itemNumber: java.lang.Integer,
state: java.lang.String,
quantity: BigDecimal
): this(
locationNumber.toInt(),
itemNumber.toLong(),
state.toString(),
quantity.toDouble()
)
}