Menu
How you could assign throwing an exception to a variable? What is a type of such variable? val d: () -> Nothing = Now imagine that one branch of this if would end with an exception val res: Int = if(cond) 1 else throw Exception(.) In Kotlin an if is an expression so you can assign it to a value val cond=Math.random() > 0.5 val res: Int = if(cond) 1 else 2 Why complete type system is so important? Without it you are unable to treat each expression as a value because what would be the value of : throw new RuntimeException(.) In this section we will focus on explaining how Kotlin Type System is built and how not having 'holes' in a system allow use to tread each instruction as a an expression which has a value.
0 Comments
Leave a Reply. |