سؤال

Is it possible to extract type parameters in Scala like this:

def some[T <: Either[A, B]](implicit ta: TypeTag[A], tb: TypeTag[B]): T = {
  // A =:= String
  // B =:= Int
  // ...
}

some[Either[String, Int]]()

?

هل كانت مفيدة؟

المحلول

You could rewrite your method like this:

def some[A, B](implicit ta: TypeTag[A], tb: TypeTag[B]): Either[A, B] = ???
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top