Uncategorized

Basic Types and Operations

  • Byte, Short, Int, Long, Char = integral types; + Float, Double = numeric types
  • Raw strings are represented with three double quotation marks. Raw strings can contain quotation marks, new lines, etc. eg.
println("""something which has "quotation" 
and spans multiple lines""")
  • Use Strip Margin method to remove empty spaces above:
println("""|the pipe strings
|will appear in same column""".stripMargin)
  • Operators are¬†methods!
  • Infix operator notation means the method to invoke sits between the object and the parameter or parameters you wish to pass to method, e.g. 7 + 2 or s indexOf ‘a’
  • Prefix notation is when you put method name before the object on which you are invoking the method, e.g. the ‘-‘ in -7
  • Postfix notation is when you put the method after the object, for example the “toLong” in “7 toLong
  • Prefix and postfix are unary:¬†they take just one operand, unlike infix
  • You can leave off empty parentheses on method calls, e.g. s.toLowerCase (which in turn can be written as s toLowerCase using postfix operator notation). By convention, you include parentheses if the method has side effects, e.g. println()
Advertisements