0

When attempt to overload constructor argument of case class :

 case class Node(var isVisited: Boolean, adjacentNodes: scala.collection.mutable.MutableList[Node], name: String) {
    def this(name : String) = this(isVisited , adjacentNodes , name)
  }

receive this error : not found: value isVisited

Should this not work as explained in accepted answer of :

Overload constructor for Scala's Case Classes?

However,this works, although not using a case class :

 class Node(var isVisited: Boolean, adjacentNodes: scala.collection.mutable.MutableList[Node], name: String) {
        def adjacentNodes(): scala.collection.mutable.MutableList[Node] = { adjacentNodes }
        def name(): String = { name }
      }

      object Node {
        def apply(name: String): Node = new Node(false, scala.collection.mutable.MutableList[Node](), name)
      }
Community
  • 1
  • 1
blue-sky
  • 51,962
  • 152
  • 427
  • 752

1 Answers1

3

isVisited and adjacentNodes do not exist for the overloaded constructor. It looks like you intend to use false and an empty list if they are not provided:

case class Node(var isVisited: Boolean, adjacentNodes: scala.collection.mutable.MutableList[Node], name: String) {
    def this(name : String) = this(false, scala.collection.mutable.MutableList[Node](), name)
}
Lee
  • 142,018
  • 20
  • 234
  • 287