There are some corner cases but the basic rule is that you need an odd number of arguments if you wish leave out the '.'.
Examples:
- scala> "hello" substring (1,3)
- res0: java.lang.String = el
- scala> "hello" substring 1
- res1: java.lang.String = ello
- scala> 1 toString ()
- res2: java.lang.String = 1
Precendence runs left to right so:
- "hello" contains "hello world" toString ()
becomes
- "hello".contains("hello world").toString()
Another example:
- scala> "hello" contains "hello world" toString () substring 4
- res6: java.lang.String = e
- scala> "hello".contains("hello world").toString().substring(4)
- res7: java.lang.String = e
There is some operator precendence which we will cover later. Operator precedence allows statements like the following:
- scala> "hello" substring 6 - 4
- res8: java.lang.String = llo
- scala> "hello" substring (6 - 4)
- res9: java.lang.String = llo
- scala> "hello".substring (6 - 4)
- res10: java.lang.String = llo
No comments:
Post a Comment