All instances are created simultaneously.
enum class Foo(input: String) {
ONE("one"),
TWO("two");
init {
println("Received $input")
}
}
fun main(args: Array<String>) {
Foo.ONE
}
When I ran this, I got the following:
Received one
Received two
If they were created lazily, I would expect that I would only print “Received one”.
source
share