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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:25:55+00:00 2026-05-14T14:25:55+00:00

I was playing around the other day with making a class to handle some

  • 0

I was playing around the other day with making a class to handle some arithmetic operations (yes, I know numeric is coming out in 2.8) and found myself wondering how to simplify the following:

def Foo[A]( _1:A, _2:A ) = (_1, _2) match{
    case _1:Bar, _2:Bar => _1 + _2
    case _1:Baff, _2:Baff => _1 push _2
    case _, _ => None
}

so that I can do just

def Foo[A]( _1:A, _2:A ) = _1 match{
    case _1:Bar => _1 + _2
    case _1:Baff => _1 push _2
    case _ => None
}

Granted, I know that in declaring the function the way it’s been declared that _2‘s type could conceivably inherit from _1‘s type, “A” could be a shared trait, or so on. I know this means the compiler needs to protest to protect the code. Is there a way to say “I want _1 and _2 to be the same extact class” so that I don’t have to make the double _1:Int, _2:int declaration?

  • 1 1 Answer
  • 1 View
  • 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-05-14T14:25:55+00:00Added an answer on May 14, 2026 at 2:25 pm

    Perhaps Im misunderstanding you, but if you just want the two parameters to be required to be the same type, you can do something like the following:

    def Foo[A,B >: A <: A](_1: A, _2:B) = ...
    

    This specifies that B is both lower and upper type bounded by A, thus must be A. Thus it will only compile if _1 and _2 are of the same type.

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

Sidebar

Related Questions

So I was playing around the other day just to see exactly how mass
I'm playing around with Java's reflection API and trying to handle some fields. Now
I've been playing around with blocking out other divs on button press, and Block
I started playing around with web2py the other day for a new project. I
I was playing with some ruby the other day and I wrote the following
been playing around with ResolveClientUrl(~/Confirmation.aspx) and other methods.. I am tryin go get the
Was playing around a little bit with the TimeSpan class and I started wondering
I am just playing around with threads in java. I have a class which
I have been playing around with various methods of making the Visitor pattern in
I'm playing around with the SQLiteDatabase class and did't understand why the insert method

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.