Scala extended constructor

Say I have:

class DecisionTree(private val instances: Array[Instance]){

and I want to calculate another instance variable, say totalEntropy, that requires me to do some further processing that will require instantiating a hashmap as part of the calculations.

I've come up with:

private var totalEntropy = (() => {
  val m = collection.mutable.Map()
  ...
})()

but this seems awkward. Should I just forgo the arguments in the class definition altogether and use an auxiliary constructor? What is a good way of doing this?

Answers


Why not just this?

private var totalEntropy = {
  val m = collection.mutable.Map()
  ...
}

Need Your Help

Login check with ajax

php mysql ajax

I have an ajax function in my index file: