Collection.plus operator is not optimal

Why a plus operator creates every single time new instance of ArrayList? When I use method add() from ArrayList, the data inside is copying only if array inside is insufficient. Isn’t it a bug?

nobody is expecting side effects in operators.

imagine writing something like std:cout << “asd”; thats horrible :smiley:

btw there is += for mutable collections which does what you want

2 Likes