Is it possible that java code generated by `Show k...
# announcements
s
Is it possible that java code generated by
Show kotlin bytecode -> Decompile
gives a different result than running kotlin code?
i
Definitely. Not every sequence of bytecode instructions can be decompiled to valid java code.
s
I have code as below:
Copy code
fun main(args: Array<String>) {

    val demo = Demo()
    demo.printNumber()
}

class Demo {

    private val number
        get() = if (isValid) 0 else 1

    private val intHolder = SomeIntHolder(number)

    private val isValid = true

    fun printNumber() {
        println(intHolder.number)
    }

}

class SomeIntHolder(val number: Int)
In kotlin it prints
1
, but generated java code prints
0
. It's pretty strange for me. Can you explain me why generated output is different?
@ilya.gorbunov Also there is another problem, but with lint, in code above lint underlines
if(isValid)
and shows
Condition is always true
, but after quick fixing (
Alt+Enter -> Simplify code
) kotlin prints different result. In this example order of properties is important, so lint is wrong. It's true only if
private val isValid = true
is above
private val intHolder = SomeIntHolder(number)
.
g
Does this imply that java re-orders initializers to run constant-assignments before expression-assignments?