Can access class parameters and default arguments if you leave them off
Can access class parameters and specify arguments in any order if you use their names:
When calling methods and functions, you can use the name of the variables explicitly in the call, like so:
When calling methods and functions, you can use the name of the variables explicitly in the call, like so:
def printName(first:String, last:String) = { println(first + " " + last) } printName("John","Smith") // Prints "John Smith" printName(first = "John",last = "Smith") // Prints "John Smith" printName(last = "Smith",first = "John") // Prints "John Smith"
Note that once you are using parameter names in your calls, the order doesn't matter, so long as all parameters are named. This feature works well with default parameter values:
def printName(first:String = "John", last:String = "Smith") = { println(first + " " + last) } printName(last = "Jones") // Prints "John Jones"
Given classes below:
class WithoutClassParameters() { def addColors(red: Int, green: Int, blue: Int) = { (red, green, blue) } def addColorsWithDefaults(red: Int = 0, green: Int = 0, blue: Int = 0) = { (red, green, blue) } } class WithClassParameters(val defaultRed: Int, val defaultGreen: Int, val defaultBlue: Int) { def addColors(red: Int, green: Int, blue: Int) = { (red + defaultRed, green + defaultGreen, blue + defaultBlue) } def addColorsWithDefaults(red: Int = 0, green: Int = 0, blue: Int = 0) = { (red + defaultRed, green + defaultGreen, blue + defaultBlue) } } class WithClassParametersInClassDefinition(val defaultRed: Int = 0, val defaultGreen: Int = 255, val defaultBlue: Int = 100) { def addColors(red: Int, green: Int, blue: Int) = { (red + defaultRed, green + defaultGreen, blue + defaultBlue) } def addColorsWithDefaults(red: Int = 0, green: Int = 0, blue: Int = 0) = { (red + defaultRed, green + defaultGreen, blue + defaultBlue) } }
Can specify arguments in any order if you use their names:
Can default arguments if you leave them off:
Can default class parameters and have default arguments too
Default parameters can be functional too
This method has been deprecated in favor of macro assertion and will be removed in a future version of ScalaTest. If you need this, please copy the source code into your own trait instead.
This method has been deprecated in favor of macro assertion and will be removed in a future version of ScalaTest. If you need this, please copy the source code into your own trait instead.
This method has been deprecated in favor of macro assumption and will be removed in a future version of ScalaTest. If you need this, please copy the source code into your own trait instead.
This method has been deprecated in favor of macro assumption and will be removed in a future version of ScalaTest. If you need this, please copy the source code into your own trait instead.
Please use 'an [Exception] should be thrownBy { ... }' syntax instead
This expect method has been deprecated. Please replace all invocations of expect with an identical invocation of assertResult instead.
This expect method has been deprecated. Please replace all invocations of expect with an identical invocation of assertResult instead.
This expectResult method has been deprecated. Please replace all invocations of expectResult with an identical invocation of assertResult instead.
This expectResult method has been deprecated. Please replace all invocations of expectResult with an identical invocation of assertResult instead.