to the end (after the lazy val) it does not throw the exception.
Copy code
fun main() {
Example()
}
class Example {
init {
freeze()
}
val value by lazy { 1 }
}
d
Dominaezzz
07/29/2019, 1:02 PM
Ideally it shouldn't but it does. It's bug territory.
š 1
Dominaezzz
07/29/2019, 1:02 PM
The same problem exists for subclasses. If the parent class freezes in
init
, then the subclass can't initialize itself.
o
olonho
07/29/2019, 1:16 PM
it's kind of intended. After freeze any mutation (including init of the field) is disallowed. Following code throws the same exception as well:
Copy code
class Example {
init {
freeze()
}
val value = 1
}
t
Thomas
07/29/2019, 1:25 PM
@olonho Ok, thanks thatās clear to me. So can I assume that freezing in a class happens from ātop to bottomā? Is it safe to freeze a class inside init if it contains field above the init?