This is kind of equivalent:
object SomeClass {
case class Options(option1: String, option2: Boolean)
}
class SomeClass(options: Options) {
//this is constructor!
println(options.option1)
}
object Main extends App {
val options = SomeClass.Options("One", false)
//or even: SomeClass.Options(option1 = "One", option2 = false)
val sc = new SomeClass(options)
}
More about nested classes (don't confuse with inner classes in Java): Static inner classes in scala.
Comments:
Options
is nested inside SomceClass
object, not class
Options
can be a case class
- this way you get immutability and accessors for free
- In Scala you have one primary constructor defined in very concise way
- Various: Scala uses pass by reference by default and all variables are actually pointers (less extra symbols compared to C++).