Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
https://www.quora.com/Is-Kotlin-so-similar-to-Scala-What-are-the-differences/answer/Bruce-Richardson-4
Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
https://www.quora.com/Is-Kotlin-so-similar-to-Scala-What-are-the-differences/answer/Bruce-Richardson-4
Iterable
(due to design reasons).
There is no super class of array and Iterable
either in Java.
If you want a method to support both array and Iterable
as the parameter,
you need to overload it (for both array and Iterable
.)
It is the same situation in Kotlin as Kotlin is mostly Java.When you use 1L shl 2
,
shl
is considered as the left-shift operator
instead of a method call.
Bitwise operators are computed from left to the right.
Bitwise operators have relatively low priority (lower than arithmatic operators), It is suggested that you use parentheses when you mix lower precendenc (bitwise opertors, ternary opertor, etc.) and high precendenc operators together. A even better approach in Kotlin is to avoid using bitwise operators and use the corresponding methods instead.
fold
takes an initial value,
and the first invocation of the lambda you pass to it
will receive that initial value
and the first element of the collection as parameters.
reduce
doesn't take an initial value,
but instead starts with the first element of the collection as the accumulator (called sum in the following example).
Iterable
,
the map
method of all collections (including HashMap
) in Kotlin returns List.