https://kotlinlang.org logo
#language-evolution
Title
# language-evolution
e

eygraber

11/26/2023, 6:29 PM
Has there ever been discussion about an annotation to disallow trailing lambdas for a given function? For example
Copy code
fun handleClicks(
  onClick: () -> Unit,
  onLongClick: () -> Unit
)
loses context when called like
Copy code
handleClicks(
  onClick = {...}
) {
  ...
}
8
💡 5
w

wasyl

11/26/2023, 7:12 PM
Related, I'd definitely use an annotation that strongly suggests that a function should be called only using named parameters
p

PHondogo

11/26/2023, 7:16 PM
Ugly solution:
Copy code
fun handleClicks(
  onClick: () -> Unit,
  onLongClick: () -> Unit,
  noLambda: Nothing? = null
)
m

mbonnin

11/26/2023, 7:34 PM
e

ephemient

11/26/2023, 10:01 PM
🌟 4
r

Ruckus

11/30/2023, 4:17 PM
Also, instead of
noLambda: Nothing? = null
, I would recommend
vararg noLambda: Nothing
, It reduces the potential confusion of something like:
Copy code
handleClicks(
    { ... },
    { ... },
    someFunctionThatReturnsNull(),
)
Though it's probably not a big deal.
👍 1
2 Views