Ayden
08/21/2018, 3:27 PMval a = 5
val b = 5.4
val c = 5.4321codyoss
08/21/2018, 3:29 PMSteven McLaughlin
08/21/2018, 3:40 PMprintln(a.javaClass.kotlin)
println(b.javaClass.kotlin)
println(c.javaClass.kotlin)karelpeeters
08/21/2018, 3:52 PMa.javaClass.kotlin.java.kotlin then.diesieben07
08/21/2018, 4:14 PMSteven McLaughlin
08/21/2018, 5:03 PMAyden
08/21/2018, 5:18 PMdiesieben07
08/21/2018, 5:19 PMval a: Any = 1 has runtime type Int but static type Any.Ayden
08/21/2018, 5:19 PMval a = 1
In runtime it shows Int but in static it is Any?diesieben07
08/21/2018, 5:21 PMInt for a, so both static and runtime type will be Int. But take this more complicated example:
fun iReturnAny(): Any = 3
val a = iReturnAny()
Compiler will infer Any for a (because iReturnAny() returns Any), but runtime type will Int.Ayden
08/21/2018, 5:22 PMAyden
08/21/2018, 5:22 PMAyden
08/21/2018, 5:23 PMAyden
08/21/2018, 5:23 PMdiesieben07
08/21/2018, 5:24 PMAny. The static type will always be Any, but the runtime type could be String (if there is a string in there) or anything else.diesieben07
08/21/2018, 5:24 PMAyden
08/21/2018, 5:26 PMdiesieben07
08/21/2018, 5:27 PMdiesieben07
08/21/2018, 5:27 PMdiesieben07
08/21/2018, 5:28 PMval a = 3 - What type does a have? Well, it's an Int, "obviously", so let's "type that for you":
val a: Int = 3diesieben07
08/21/2018, 5:28 PMkarelpeeters
08/21/2018, 5:30 PMCtrl + Q on the variable.Ayden
08/21/2018, 5:31 PM