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:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.