How can I pass the reference of an object to method in Scala? E.g. I want this to compile
object Constants {
val constantA:Double = ???
}
def calc(number
You can use the Any type
def calc(numbers:Seq[Double], constants: Any)
but this wouldn't allow you to access the constantA value. Alternatively you could define a trait with the constant and let you object implement that:
trait ConstantA {
val constantA:Double
}
object Constant extends ConstantA {
override val constantA:Double = 0.0
}
def calc(numbers:Seq[Double], constants: ConstantA) {
...
// use constants.constantA
println(constants.constantA)
...
}