In a let
block, I sometimes see ^let
annotations before my statements, and it's not clear to me what they mean or why they are there.
Is it to indicate that a value will be returned as the value of the let
call?
Screenshot:
Android Annotations is an annotation-driven framework that allows you to simplify the code in your applications and reduces the boilerplate of common patterns, such as setting click listeners, enforcing ui/background thread executions, etc.
The annotation processor can validate, generate, and modify your code based on the annotations, which help you significantly reduce the amount of code you need to write. The annotation processor could be stored inside your project. In this case IntelliJ IDEA obtains it from the classpath.
To configure annotation processing in IntelliJ IDEA, use dialog Preferences > Project Settings > Compiler > Annotation Processors. Obtain annotation processors from the project classpath and specify output directories. After you do this, classes will be generated on each project build.
These do in fact show you that those values are going to be returned from the let
expression. If you move to cursor to one of these hints and open intention actions (Alt + Enter), you get the option "Do not show lambda return expression hints", which I suppose is the name for this new feature.
This change was introduced in Kotlin 1.2.20, see IntelliJ IDEA Plugin Improvements in this post.
Your screenshot demonstrates two new IDE features that were introduced with Kotlin Plugin 1.2.20:
KT 20533 Show "this" and "it" type hints in lambdas.
KT-20067 Return label hints
Here’s the description of KT-20066 that’s related to the question:
Returns from lambdas can be confusing, especially when lambdas are nested or crossinline. It is often difficult to determine the lambda's return type and where a block is returning to, which may cause subtle compilation errors or runtime bugs. One solution is to always use explicit labeled returns and type signatures, however this can add extra noise to the source code. One suggestion for improving readability is to use IDE hinting (like in parameter hints), for lambda returns in Kotlin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With