Gyuhyeon
01/06/2020, 7:57 AMclass UserModel(
val memberKey: Long? = null // val memberKey: Long doesn't work, because it won't create a noarg default constructor - MyBatis doesn't work without a default constructor. Therefore, we have to supply a default value to it.
)
However, memberKey being nullable creates headaches in the business logic because !!
or .?
has to follow around all the frickin time.
Some people could recommend something like this:
class UserModel(
val memberKey: Long = 0L
)
But, this creates another pack of worms since omitting memberKey by accident in the business logic will result in inserting a user with literally 0L memberKey, which leads us to validating != 0
manually in @Service
or wherever appropriate.
What I would've done if Long wasn't a primitive is
class UserModel{
lateinit var memberKey: Long
}
But alas, Kotlin, due to its infinite wisdom, has decided against supporting lateinit
in primitives.
Any thoughts?Isaac Udy
01/06/2020, 8:05 AMIsaac Udy
01/06/2020, 8:08 AMdata class MyClass(
private val _id: Long = 0,
...,
...
) {
val id: Long get() {
return if(_id == 0) throw RuntimeException() else id
}
}
James Richardson
01/06/2020, 8:11 AM<constructor>
tag or @Constructor
annotation. May be wrongaudriusk
01/06/2020, 11:08 AMclass UserModel {
var memberKey: Long by notNull()
}
Daniel
01/06/2020, 12:41 PMLevelRoomEntity
in my project which is the object saved by the room database and then I map/convert it to a Level
which does not know anything about roomDaniel
01/06/2020, 12:43 PMvar
fields if need be. This would be fine since it would never be used in business codeGyuhyeon
01/07/2020, 1:43 AM