https://kotlinlang.org logo
Title
r

Ryan

06/04/2020, 11:55 AM
i’m a big fan of never using lateinit
m

Michael de Kaste

06/04/2020, 12:03 PM
There are some exceptions that there is no workaround, especially in Java library conversion usage in kotlins, but mostly yes
m

Mike

06/04/2020, 12:03 PM
Why is that?
r

Ryan

06/04/2020, 12:04 PM
because the “by” operator exists.
j

Joel

06/04/2020, 12:06 PM
@Michael de Kaste is correct - when you are interacting with Java libraries there are points where you must behave like Java. I've found that JPA/Hibernate entities are much easier to write using
lateinit var
because that is how the underlying mechanics of the framework operate.
Within kotlin I would not use
lateinit
as there is always a more kotlin-ish way to write your code.
t

Tom Hermann

06/04/2020, 11:37 PM
I use it in tests for reflection based runners (like Spring's) with annotations like
@MockBean
Usually I try to avoid it, but it is there if you really need it.
👆 1
Tangent: !! In production code is what drives me crazy 🤪
r

Ryan

06/05/2020, 12:53 AM
There are no rules when writing tests 🙂