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
Constants
is an object. You don't specify objects as parameter types for method parameters, you specify types as parameter types for method parameters:
def calc(numbers:Seq[Double], constants: Constants.type) = ???
Generally speaking, more precise types are good, but in this case, it might be overdoing it with an overly precise type, since there is exactly one instance of the type Constants.type
, so you cannot ever pass anything other than the Constants
object as an argument, which makes the whole idea of "parameterizing" rather pointless.