One more thing which I use more often than 1: ```v...
# announcements
g
One more thing which I use more often than 1:
Copy code
val entity = hibernateRepository.getEntityById("some-id") ?: error("some-id is null")
1
c
this is a different case. in my example entity is always not null, I'll edit it to make that obvious
g
Anyway, I mean that to check for null I usually use elvis + error
c
I see, that's too cumbersome for general use I think. E.g. here's an example from a code base I work on currently
Copy code
class SomeEvent(
    val aEntityId: Long,
    val bEntityId: Long,
    val cEntityId: Long)

// all three are retrieved, something is done to them and event is being published:

publishEvent(
    SomeEvent(
        a.id ?: error(""),
        b.id ?: error(""),
        c.id ?: error("")
    )
)
text in error should be meaningful, so this is not something easy to read or write.
g
I agree, it’s not something completely universal