Bruno
Bruno

Reputation: 3

Does kotlin support default argument on generics like lists or maps

I see that kotlin does not support this:

fun testDefaultListArg(listArg:MutableList<String>=mutableListOf()) {
    ...
}

Is there a way to make listArg parameter accepte a default list instance value ?

Thanks

Upvotes: 0

Views: 53

Answers (1)

deHaar
deHaar

Reputation: 18558

To turn the comment given by JBNizet into an answer:
You have to put spaces before and after the equal (=) sign, like this:

fun testDefaultListArg(listArg: MutableList<String> = mutableListOf()) {
    // do what you think you have to do here
}

Upvotes: 2

Related Questions