Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

code snippet with ^let annotations

like image 521
aaaidan Avatar asked Jan 23 '18 06:01

aaaidan


People also ask

What are Android annotations?

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.

What are annotation processors in IntelliJ?

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.

How do I enable annotations in IntelliJ?

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.


2 Answers

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.

The intention action in the IDE

This change was introduced in Kotlin 1.2.20, see IntelliJ IDEA Plugin Improvements in this post.

like image 91
zsmb13 Avatar answered Oct 01 '22 07:10

zsmb13


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.

like image 43
s1m0nw1 Avatar answered Oct 01 '22 08:10

s1m0nw1