September 2019
Intermediate to advanced
462 pages
11h 3m
English
Even if a piece of code is valid syntactically, some potential problems may be lurking. Getting an early warning, during compilation time, can help us to proactively fix such possible issues. The Kotlin compiler looks out for quite a few potential issues in code.
For example, if a parameter that’s received in a function or a method isn’t used, then the compiler will give a warning. In the following script, the parameter passed to compute() isn’t used.
| | fun compute(n: Int) = 0 |
| | |
| | println(compute(4)) |
When you run this script, in addition to displaying the result, Kotlin will also report any warnings for unused parameters:
| | 0 |
| | unused.kts:1:13: warning: parameter 'n' is never used |
| | fun compute(n: Int) = 0 ... |
Read now
Unlock full access