Kroppeb
02/10/2020, 2:05 PMfun addStatement(statement: Statement?){
statement?.let{
statements.add(it)
}
}
or less indentation
fun addStatement(statement: Statement?){
statement?:return
statements.add(statement)
}
or just old reliable
fun addStatement(statement: Statement?){
if(statement != null)
statements.add(statement)
}
Kroppeb
02/10/2020, 2:19 PMstatements.add(...)
it would be a longer piece of code? Would 2 be more desired to reduce indentation?arekolek
02/10/2020, 2:22 PMfun addStatement(statement: Statement?) {
statement?.let(statements::add)
}
arekolek
02/10/2020, 2:25 PMfun addStatement(statement: Statement?) {
if (statement == null) return
statements.add(statement)
// a lot of other stuff with statement
}
if it was longerKristoffer Andersen
02/10/2020, 2:53 PMKroppeb
02/10/2020, 2:59 PML0
LINENUMBER 11 L0
ALOAD 0
DUP
IFNULL L1
GOTO L2
L1
LINENUMBER 11 L1
POP
RETURN
L2
POP
5:
L0
LINENUMBER 24 L0
ALOAD 0
IFNONNULL L1
RETURN
It's weird that the compiler does 2 in such a convoluted way.Kristoffer Andersen
02/10/2020, 3:00 PMKroppeb
02/10/2020, 3:02 PMDUP
and POP
. I find it weird they are placed there in the first place and the first non-control flow op executed afterwards is always a POP
Kroppeb
02/10/2020, 3:02 PMDaniel
02/11/2020, 6:27 PMfun addStatement(statement: Statement){
// ...
}
And don't call the method if you don't have a statement. Thats the nice thing in kotlin, you can control your api in relation to null! 🙂