Assume you write a method with type-parameter. Assume the type parameter can be (but does not have to be) an enum type. Is there a way to infer the the companion object of the enum-type from inside the method-body.
Example:
enum MyEnum
case A, B, C
def cleverMethod[T]: CoolAnswer =
// To return a cool answer, I'd love to analyze the type T and do something like:
// If it is an enum-type then find the companion object and return it wrapped into
// an instance of CoolAnswer. Or use the companion object to find all elements
// elements of the enum.
???
// Use the method with MyEnum as parameter
val test = cleverMethod[MyEnum]
// And the instance test receives now wraps the companion object.
Suggestion to the scala developers: If there is no easy way to do this yet, why not provide one in the next stage of evolution of scala? The idea might be to make the companion-object of an enumeration accessible from its type. Thanks!