Bernhard
08/10/2018, 7:45 AMnikolay
08/10/2018, 8:57 AMUzi Landsmann
08/10/2018, 9:21 AMBMG
08/10/2018, 11:12 AMPaul Woitaschek
08/10/2018, 1:06 PMtwisterrob
08/11/2018, 9:35 AMfun main(vararg args: String) {
fun toCall(arg: String) = println("fun: $arg")
val toCall = fun (arg: String) = println("val: $arg")
toCall("hello")
}
What happens? (spoilers in thread)
1: outputs "fun: hello"
2: outputs "val: hello"
3. fails to compilekotlin_questions
08/11/2018, 3:07 PMsupaham
08/11/2018, 6:49 PMSlackbot
08/13/2018, 6:10 AMnickk
08/13/2018, 10:02 AMDenis A
08/13/2018, 10:49 AMnickk
08/13/2018, 2:15 PMphoto
property is null, hasPhoto() seems to return true and control goes to the next statement (Kotlin 1.2.60)diesieben07
08/13/2018, 2:36 PMNav Singh
08/14/2018, 1:17 AMCan Orhan
08/14/2018, 12:26 PMnickk
08/14/2018, 12:28 PMrakeeb
08/14/2018, 3:46 PMjw
08/14/2018, 3:48 PMtschuchort
08/14/2018, 4:36 PMclass Base(private val x: X) {
val a: Int = throw IllegalStateException(
"something went wrong with $this") // calls Derived::toString
}
class Derived(private val x: X) : Base(x) {
override fun toString() = x.toString() //NullPtrException: x is null
}
val d = Derived(X())
How can it be that there is a NullPtrException in Derived::toString
when it's called by Base::<init>
initializing Base::a
? is Derived::x
not set before giving it to the constructor of Base
?twisterrob
08/14/2018, 7:58 PM.let<Type> { }
karelpeeters
08/14/2018, 9:56 PMAlbert
08/15/2018, 8:07 AMkotlin_questions
08/15/2018, 8:24 AMkotlin_questions
08/15/2018, 8:26 AMkotlin_questions
08/15/2018, 8:26 AMkotlin_questions
08/15/2018, 8:27 AMkotlin_questions
08/15/2018, 8:32 AMdsavvinov
08/15/2018, 8:38 AMkotlin_questions
08/15/2018, 8:39 AMSlackbot
08/15/2018, 11:31 PM