I have some Scala code with type tags that I need to make available for Java users. My problem boils down to solving the following:
Given two Scala type tags, how can I manually create a type tag for Tuple2[ A , B ]?
If it makes any difference my specific case is a bit simpler: I have one type tag for A and I need to create a type tag for Tuple2[ String , A ]
Type tags are usually used as implicits, so the implicit system is very familiar with them. Just tell Scala what type you want and ask for it implicitly.
def tupleTag[A : TypeTag, B: TypeTag]: TypeTag[Tuple2[A, B]] = implicitly
If it can be instantiated, Scala will do so. If it can't, it's a compiler error. In this case, since A and B are already concrete (in that they have tags), Tuple2[A, B] will always be concrete as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With