Klitos Kyriacou
05/01/2025, 11:02 AMfun foo() {
val a = 1
val b = a.let { it } // Highlighted with message "Redundant 'let' call could be removed
val c: Int
a.let { c = it } // No inspection! Could just be c = a.
}
phldavies
05/01/2025, 11:05 AMa.let { c = it }
is an expression
c = a
is a statement
the let
is not redundant here as removing it would change it from expression to statement ?phldavies
05/01/2025, 11:05 AMa.let { it }
and a
are both expressions with the same resulting value - hence redundantKlitos Kyriacou
05/01/2025, 11:35 AMCLOVIS
05/02/2025, 3:31 PMNow, I wonder why Kotlin makes such a big distinction between statements and expressions. Why aren't statements simply expressions of type Unit?
val a = val b = 3
With your proposal, a
is Unit
.
Probably something you'd learn to avoid quite quickly, but still a bit weird to have in a language.CLOVIS
05/02/2025, 3:32 PM