is there a way to resolve an ambiguous += to a lis...
# stdlib
s
is there a way to resolve an ambiguous += to a list?
cliOptions += CliOption()
clioptions is a java List
Copy code
Assignment operators ambiguity. All these functions match.
public operator fun <T> Collection<CliOption!>.plus(element: CliOption!): List<CliOption!> defined in kotlin.collections
public inline operator fun <T> MutableCollection<in CliOption>.plusAssign(element: CliOption): Unit defined in kotlin.collections
j
You could do
cliOptions.add(CliOption())
or
cliOptions = cliOptions + CliOption()
depending on the one you want
e
not always but often
var : MutableList
is a poor design choice anyway
plus1 1
s
@Joffrey why do i have to do
= +
? this doesn't really answer why += doesn't work, and why i have to explicitly call assignPlus()
which sucks because they're all noisier than just doing +=
e
.plusAssign
and
= .plus
are the respective meanings of
+=
with
val cliOptions: MutableList
and
var cliOptions: List
respectively. but if you have a
var cliOptions: MutableList
then
+=
is ambiguous