What are the `^let` annotations in Android Studio / IntelliJ?

﹥>﹥吖頭↗ 提交于 2020-06-25 09:11:33

问题


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.



来源:https://stackoverflow.com/questions/48395318/what-are-the-let-annotations-in-android-studio-intellij

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!