Add operator (e1.operator_add(e2))

24 views
Skip to first unread message

Jon Rustand

unread,
Mar 8, 2016, 7:41:15 AM3/8/16
to Xtend Programming Language
Hi,

In the code sample below, two Path elements are added (one for data and one for temp), is this a bug ?

import java.util.List
import java.nio.file.Path
import java.util.ArrayList
import java.nio.file.Paths

class PathAdd {
def static void main(String[] args) {

val List<Path> paths = new ArrayList
val path = Paths.get('c:/data/temp')

paths += path
println(paths.size) // => 2
}
}

Regards
Jon 

Artur Biesiadowski

unread,
Mar 8, 2016, 8:53:28 AM3/8/16
to Xtend Programming Language
When in doubts, look at generated code to see what is happening (Windows->Show View, Xtend->Generated Code).

final Path path = Paths.get("c:/data/temp");
Iterables.<Path>addAll(paths, path);

As Path is Iterable, += is interpreted as addAll, rather than just add.
Reply all
Reply to author
Forward
0 new messages