https://kotlinlang.org logo
#announcements
Title
# announcements
t

tianhao

10/19/2017, 5:34 AM
@jw this is java way and it works
return list.stream().allMatch(new HashSet<>()::add);
i

ilya.gorbunov

10/19/2017, 12:37 PM
And the equivalent in Kotlin would be:
Copy code
listOf(1,2,3,1,2,3).all(HashSet<Int>()::add)
t

tianhao

10/19/2017, 12:40 PM
@ilya.gorbunov unfortunately, this code can’t get compiled
i

ilya.gorbunov

10/19/2017, 12:41 PM
Do you use Kotlin 1.1.x?
t

tianhao

10/19/2017, 12:44 PM
ah, yeah, sorry it works as initially i used
{}
instead of
()
Thanks
But curiosity, why the following code behaves different,
listOf(1,2,3,1,2,3).all { HashSet<Int>().add(it) }
Ok, got it, stupid conversion tool, it’s a bug of that
3 Views