What are the `^let` annotations in Android Studio

2020-08-26 03:31发布

问题:

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:

回答1:

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.



回答2:

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.