79150279

Date: 2024-11-02 08:55:39
Score: 1
Natty:
Report link

I am new to kotlin but you made me learn this today, thanks! was using kotlin playground..


You were asking about way to add one more argument with default value without breaking existing calls.

You can do this by using attributes after vararg like

fun foo(
    id: String,
    vararg values: Int,
    attributes: Array<String> = arrayOf("a", "b"),
){
  ...
}

But wait, that will raise error regarding type, because the attribute which you meant to convey at last of foo() will also be considered as vararg, so to use this code we will have to call the function like:

foo("id_3", 1, 2, 3,attributes=loremipsum)

wherever required you can add ,attributes=loremipsum and if not leave it.

Reasons:
  • Blacklisted phrase (0.5): thanks
  • RegEx Blacklisted phrase (1.5): I am new
  • Long answer (-0.5):
  • Has code block (-0.5):
Posted by: redoc