Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7748473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:47:39+00:00 2026-06-01T10:47:39+00:00

Im having an issue over loading the constructors in Scala. Each time I try

  • 0

Im having an issue over loading the constructors in Scala. Each time I try to pass a value for the over loaded CTOR I get the error

Example: 
    var client : Client = Client(*variable type List[String]()*);

 Unspecified value parameter clientList.    

My goal is to have an object created using 2 different data types. One a NodeSeq and the Other a List. Never Both. Am I over loading the CTOR correctly or is there a more efficient way to achieve my goal?

package api
import xml._

case class Client(clientNode: NodeSeq, clientList: List[String]) {

  def this(clientNode: NodeSeq) = this(clientNode, null)
  def this(clientList: List[String]) = this(null, clientList)

  var firstName: String
  var lastName: String
  var phone: String
  var street: String
  var city: String
  var state: String
  var zip: String
  var products = List[String]()
  var serviceOrders = List[String]()

  if (clientList == null) {
    firstName = (clientNode \\ "firstname").text
    lastName = (clientNode \\ "lastname").text
    phone = (clientNode \\ "phone").text
    street = (clientNode \\ "street").text
    city = (clientNode \\ "city").text
    state = (clientNode \\ "state").text
    zip = (clientNode \\ "zip").text

    (clientNode \\ "products").foreach(i => products = i.text :: products)

    (clientNode \\ "serviceOrders").foreach(i => serviceOrders = i.text :: serviceOrders)

  } else {
    firstName = clientList(0)
    lastName = clientList(1)
    phone = clientList(2)
    street = clientList(3)
    city = clientList(4)
    state = clientList(5)
    zip = clientList(6)
  }

  override def toString(): String = {
    return "Name : " + firstName + " " + lastName +
      "\nAddress : " +
      "\n\t" + street +
      "\n\t" + city + ", " + state + " " + zip
  }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:47:40+00:00Added an answer on June 1, 2026 at 10:47 am

    You didn’t post working code; you can’t have undefined vars.

    Anyway, the problem is that even though you have overridden the constructors, you have not overridden the builders in the companion object. Add this and it will work the way you want:

    object Client {
      def apply(clientNode: NodeSeq) = new Client(clientNode)
      def apply(clientList: List[String]) = new Client(clientList)
    }
    

    (if you’re using the REPL, be sure to use :paste to enter this along with the case class so you add to the default companion object instead of replacing it).

    But a deeper problem is that this is not the way you should be solving the problem. You should define a trait that contains the data you want:

    trait ClientData {
      def firstName: String
      def lastName: String
      /* ... */
    }
    

    and inherit from it twice, once for each way to parse it:

    class ClientFromList(cl: List[String]) extends ClientData {
      val firstName = cl.head
      . . .
    }
    

    or you could turn the NodeSeq into a list and parse it there, or various other things. This way you avoid exposing a bunch of vars which are probably not meant to be changed later.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My friend and I are having a disagreement over an application development issue. It's
i am having issue with loading my selector via a jquery ajax load call
The issue I'm having is issue with is I'm trying to get the paintComponent
I am coding in Perl and i'm having some minor issue over here. I
Having an issue using JSTL and Spring...it's not allowing me to iterate over my
I'm having an issue where the gray overlay that's automatically put over my UISearchDisplayController
Having an issue with a custom iterator in that it will only iterate over
I'm having an issue finding out how to calculate an average over x days.
I'm having an issue with a catch-all rule in .htaccess that is over-riding all
I am still having a issue getting over a small issue when it comes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.