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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:28:32+00:00 2026-05-22T17:28:32+00:00

I noticed that tuple.productIterator always returns an Iterator[Any] an wondered if it’s not possible

  • 0

I noticed that tuple.productIterator always returns an Iterator[Any] an wondered if it’s not possible to set multiple lower bounds (so it could be an Iterator of the lowest common super type).

I tried and searched a bit, but only found this question for multiple upper bounds.

This is my test on how to define the the type of the iterator:

def f[A,B](a:A, b:B) = List(a,b)
// return type is List[Any]

def f[A,B, T >: A "and" T >: B](a:A, b:B) = List[T](a,b)
// doesn't compile, but
//  f(1, true) should give a List[AnyVal] and
//  f("x", "y") a List[String]

Is this a limitation of the JVM?


Edit:
Here’s a slightly bigger example which doesn’t seem to be solvable using IttayD approach when T should be defined in the method:

class Foo[A, B](a: A, b: B) {
  def f[T >: A] = List[T](a) // works
  def g[T >: A "and" T >: B] = List[T](a) // doesn't work
}
  • 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-05-22T17:28:33+00:00Added an answer on May 22, 2026 at 5:28 pm

    For the simple case where A and B are bound by the compiler as the same time as T, IttayD’s answer works fine:

    def f[T, A <: T,B <: T](a:A, b:B) = List[T](a,b)
    

    When A and B are already bound as in your class Foo[A, B] example, you need to introduce temporary dummy variables to have the compiler do this job:

    class Foo[A, B](a: A, b: B) {
      def g[T, A1 >: A <: T, B1 >: B <: T] = List[T](a: A1, b: B1)
    }
    

    (For the sake of clarity: A1 >: A <: T means that type A1 must be a supertype of A and a subtype of T, and not that A is a subtype of both A1 and T.)

    A1 and B1 are here for the sole purpose of inferring a correct type for T. If the compiler has to infer them, they will resolve to A1 = A and B1 = B, and then T as the most specific type which is a superclass of both A and B.

    One thing that the compiler doesn’t realize, though, is that, by transitivity, we have both T >: A and T >: B, which follows directly from the constraints with respect to A1 and B1. We need to help out with the type ascriptions.

    Now, Product#productIterator could not use this technique, as it’s defined in a place where we don’t even know A and B, or indeed how many type parameters there are in the concrete subclass.

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

Sidebar

Related Questions

i noticed that paypal displays a very different favicon, one that's not just a
I noticed that i can set a return type on a function to 'Void'
I noticed that Facebook added a place to explicitly set the height of the
I noticed that itertools does not (it seems to me) have a function capable
I noticed that GoogleToolbarNotifier.exe cannot be killed from Process Explorer. It returns Access Denied.
I noticed that if you copy-paste web browser content into Notepad (or any text
I noticed that cherrypy session does not require a secret key configuration. On the
I noticed that the Left property for TTabSheet in the TPageControl is always 4.
I noticed that Google maps is providing directions in my local language (hungarian) when
I noticed that you can call Queue.Synchronize to get a thread-safe queue object, but

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.