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 8623373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:15:54+00:00 2026-06-12T07:15:54+00:00

I have the something akin to the following code (only with more parameters) in

  • 0

I have the something akin to the following code (only with more parameters) in a program I am developing:

class Particle {
   //variables
   def this(position: Position2D, velocity: Vector2D) = {
   this()
   //constructors
   }

   def this(xPos: Double, yPos: Double, magnitude: Double, angle: Double) = {
   this(new Position2D(xPos, yPos), new Vector2D(magnitude, angle))
   }
}

And I would like to make it so that the program is able to accept the Position2D object for the first parameter and two Doubles for the second parameter, or two Doubles for the first parameter and a Vector2D object for the 2nd parameter, without creating more this statements for each combination of parameters. I know that it’s possible to use something like:

def this(posObj: Either[Position2D, Array[Double]], velObj: Either[Vector2D, Array[Double]]) = {...}

And then test to see what type posObj and velObj are; however, I was curious if there was a way to do this without requiring the 2nd part of the Either to be just one item such as an Array, so that you could initialize Particle like the following:

val a = new Particle(new Position(3, 6), 30, 5)
val b = new Particle(3, 6, new Vector2D(30, 5))
val c = new Particle(new Position(3, 6), new Vector2D(30, 5))
val d = new Particle(3, 6, 30, 5)
  • 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-12T07:15:55+00:00Added an answer on June 12, 2026 at 7:15 am

    The short answer is no, the constructors are rigid in the sense that the number of parameters (assuming you don’t want them in a Seq) for a method (or constructor in this case) has to be quite specific.

    Potentially by enclosing the naked pairs in a Tuple2 and creating a typeclass instance to unpack each this would be possible, but it would be an order of magnitude more complicated than just adding the constructors.

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

Sidebar

Related Questions

I have something akin to the following: public class X extends Thread{ BufferedInputStream in
Does NetBeans have something akin to Set Next Statement/Instruction when debugging in Java?
I have something like this: function showFunction () { // need position and place
I have something like the code below: for(int i=0;i<10;i++){ button=new JButton(buttons[i]); button.addActionListener(new ActionListener(){ public
I have something like this: <?xml version=1.0 encoding=utf-8?> <Data> <ConfigDatas> <ArrayOfConfigData xmlns:i=http://www.w3.org/2001/XMLSchema-instance xmlns=http://schemas.datacontract.org/2004/07/BTTest.Models> <ConfigData>
I have something like this: [{'date': 1, 'value':5}, {'date':2,'value':3}, ...] and want to map
I have a data.frame that has a number of duplicate rows, akin to something
I have something akin to <Foobar Name='Hello There'/> and need to change the single
Does windows have any decent sampling (eg. non-instrumenting) profilers available? Preferably something akin to
So I have the following test code: #include <string.h> #include <stdio.h> int main(int argc,

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.