Why Curly braces doesn't work instead of parenthesis calling apply method in scala -
afaik, in scala, 1 can choose use either curly braces {}
or parenthesis ()
sending arguments method.
math.abs{-10} def fx(x: int) = x * x fx{10} list(1, 3, 5, 7) filter { _ > 5}
so, why not applicable apply method in object list?
list.apply{"a", "b"} // not compile
when call method can pass parameters or inside parentheses or without them if has 1 argument. here fx {10}
pass block of return type int {10}
without parentheses. it's equivalent fx({10})
.
here list(1, 3, 5, 7) filter { _ > 5}
pass block { _ > 5}
of return type int => boolean
without parentheses.
in both above cases last block statement legal expression.
here list.apply{"a", "b"}
pass without parentheses block {"a", "b"}
equivalent list.apply({"a", "b"})
, "a", "b"
statement illegal in scala.
Comments
Post a Comment