Laurent Laborde
09/05/2022, 4:27 PMKlitos Kyriacou
09/05/2022, 5:28 PMlateinit
was more readable than other ways.Laurent Laborde
09/05/2022, 7:16 PMLaurent Laborde
09/05/2022, 7:16 PMLaurent Laborde
09/05/2022, 7:18 PMKlitos Kyriacou
09/06/2022, 8:07 AMlateinit
is not allowed on primary constructor parameters. So you would have to have it in a property defined inside the class body instead, and then it wouldn't take part in the methods automatically created by the data class such as equals
.Ruckus
09/06/2022, 5:45 PMButThat would be rather pointless. How do you not initialize a passed in value?is not allowed on primary constructor parameterslateinit
Jackson Cleary
09/06/2022, 11:53 PMlateinit
a property of a data class? As @Klitos Kyriacou alluded, it would defeat the purpose of using a data class anyway.
I’m of the opinion lateinit
should be avoided in most cases, as it is effectively breaking null safety and lead to runtime exceptions. There’s usually better (safer) ways to handle things. Only time I’d usually make an exception is for things like butterknife or mockito where we want to inject some value.