Thread
#stdlib
    Pere Casafont

    Pere Casafont

    3 years ago
    Is there a way to get a use of
    MutableCollection::plusAssign(Iterable)
    to compile without having assignment operators ambiguity error? Here an example that does not compile:
    val list = listOf(1, 2, 3)
    	var mutableList = mutableListOf(4, 5, 6)
    	mutableList += list
    gildor

    gildor

    3 years ago
    Only if you replace
    var
    with
    val
    If you need
    var
    there, than use addAll instead:
    mutableList.addAll(list)
    Pere Casafont

    Pere Casafont

    3 years ago
    oh, yes I need var in my case, and now I understand what's up; thanks!
    however, maybe it'd be nice if
    plusAssign
    had preference over
    plus
    +
    assign
    to avoid this odd situation
    gildor

    gildor

    3 years ago
    mutableList += list
    is acutally reassign mutableList, but (mutableList + list) returns List, so type is not compatible, so it’s not clear how you can solve it