I have these two enums:
enum Season:
case Warm, Cold
enum Territory:
case Continente, Madeira, Açores
I want to create a method radioInputsFor
which receives the enum type and a concrete enum value such that these invocations are valid:
radioInputsFor(Season, Season.Warm)
radioInputsFor(Season, Season.Cold)
radioInputsFor(Territory, Territory.Madeira)
And these invalid:
radioInputsFor(Season, Territory.Madeira)
radioInputsFor(Territory, Season.Cold)
I also want to invoke .values
on the first parameter inside the method.
What are the correct generics and types I should use for the parameters?
This
def radioInputsFor[T <: Enum](default: T): T = default
Correctly restricts the first parameter to be an enum value. However I cannot find a suitable type that abstracts the enum type.
Edit: currently this is not possible. However this PR is adding the required functionality.