sikri
11/26/2019, 10:43 AMlistOf(a, b, listOf(c, d).toTypedArray())
Even though, SpreadBuilder.addSpread
supports Collections and Iterators, based on this,
public void addSpread(Object container) {
...
else if (container instanceof Collection) {
list.addAll((Collection) container);
}
else if (container instanceof Iterable) {
for (Object element : (Iterable) container) {
list.add(element);
}
}
...
}
I cannot write code like this, even though it seems being supported:
listOf(a, b, listOf(c,d))
This leads to this in bytecode:
L41
LINENUMBER 154 L41
ALOAD 15
ICONST_0
ANEWARRAY pl/some/type
INVOKEINTERFACE java/util/Collection.toArray ([Ljava/lang/Object;)[Ljava/lang/Object; (itf)
L43
ASTORE 21
ALOAD 13
ALOAD 12
ALOAD 21
INVOKEVIRTUAL kotlin/jvm/internal/SpreadBuilder.addSpread (Ljava/lang/Object;)V
And as you can see, there is a useless array copydiesieben07
11/26/2019, 10:46 AMsikri
11/26/2019, 10:48 AMI suppose it might be sufficient to start with adding spread support only for Collection and to postpone spread-convention until it is proved to be useful for other use-cases.
😒ad:diesieben07
11/26/2019, 10:48 AM