Add annotation (or other mechanism) to force named arguments for method

It would be nice to have some kind of annotation (or other mechanism) which will force caller to use named arguments.

For instance to call this method:

@NamedArgsOnly
fun buildSomeInstance(param1: Boolean = true, param2: Boolean = false /* so on */)

Developer will be bound to use named arguments:

buildSomeInstance(param1=false, param2=true)

This would be useful for creating builders. It will improve readability

3 Likes

I like the idea. There already is a similar issue on youtrack: https://youtrack.jetbrains.com/issue/KT-14934
It’s a feature request to decide this for each parameter separate.

2 Likes