Take the map function of any collection type:įun map ( list : List, f : ( A ) -> B ): List Īs we might guess, using checked exceptions for the function f is impossible since it must stay generic. ![]() In fact, if we want to use a higher-order function together with checked exceptions, we need to declare the exception in the signature of the lambda function, which is not feasible. But, checked exceptions don’t work well with higher-order functions, which are fundamental to functional programming. If a method declares to throw a checked exception, the compiler will force us to handle it. However, Kotlin doesn’t have checked exceptions. Somebody can say that the JVM also has checked exceptions and that we can use them to avoid the problem. The only place we become aware of the exception is during runtime execution, which is a bit late. However, in this case, we’re not aware that the method can throw an exception, and the compiler can not help us in any way. As developers, we want the compilers to help us avoid errors. No reference to the exception is present in the signature. ![]() We expect the method to take a job id as input and return a salary as a Double. Fun retrieveSalary ( id : JobId ): Double
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |