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

  • Home
  • SEARCH
  • 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 8091321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:01:30+00:00 2026-06-05T20:01:30+00:00

One can say a type parameter T must have a specific supertype S_1: class

  • 0

One can say a type parameter T must have a specific supertype S_1:

class Test[T <: S_1] 

Is there a way to say, that a type parameter must have at least one supertype of multiple supertype alternatives ?
Something like (pseudocode) :

class Test[T <: S_1 || S_2] 

Or: Is this not possible, because such a construction makes no sense and would be a hint of a design mistake in the code ?

  • 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-05T20:01:31+00:00Added an answer on June 5, 2026 at 8:01 pm

    Short answer: The intuitive solution is to make S_1 and S_2 share a common trait that represents the set of abilities you require for your type parameter T. Use that trait as the upper bound for T.

    More possibilities:

    • If S_1 and S_2 are unrelated in nature and your requirement for the type T is that it has certain members (that both S_1 and S_2 happen to implement), you can use a structural type to formulate that (the concept behind is called duck typing).

    • If for some reason you really require T to be a subclass of S_1 or S_2, and you can’t change those types, you can use implicits to convert both of these to a newly introduced internal type S_1_or_2, which you can then use as an upper bound for your T.

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

Sidebar

Related Questions

Let's say I have an abstract parent class called shape, and that there are
Say I have a macro, FOO(name), and some template class Bar<> that takes one
Let's say I have n marbles, and each can be one of 8 possible
I can't figure this one out. At first let me say that my cache
Possible stupid question: let's say I have two apps contained within one project. Can
Say I have a higher kinded type SuperMap[Key[_],Value[_]]`. Suppose now that I had something
Say I have a class with one property Public Class MyClass Public Property MyItem()
Let's say I have a type of lookup table which I can build for
Which one is better in, say, parameter type in a method (not related to
Is it ok to have only one model that can hold many different types

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.