How to say that a type parameter must have one supertype of alternative supertypes?
scala
Solution
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`.
Problem
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 ?