0

I have a parameterized Generic type, where the generic type is from Case classes I defined separately.

These are

case class TypeA(user_id: String, device_id: String) extends Serializable case class TypeB(user_id: String, device_id: String, org_id: String, app_name: String) extends Serializable 

I use a Map function to read in the datasets, based on the Generic type schema

val res = this.readHandlersMap.map(s => s._1 match { case "a" => { (s._1, s._2.read[TypeA]((Encoders.product[TypeA].schema)).asInstanceOf[Dataset[TypeA]]) } case "b" => { (s._1, s._2.read[TypeB]((Encoders.product[TypeB].schema)).asInstanceOf[Dataset[TypeB]]) } }); 

After checking the output of res, I get that it is of type

Map[String, Dataset[_ >: TypeA with TypeB <: Serializable with Product]] 

I don't get the meaning of this type. What do the _>: and withs do in this type? And when I try to declare res as of type Dataset[Serializable], I get an error. What will this type be if I add a TypeC?

1 Answer 1

2

These are basically upper and lower bound for the defined generic type:

For example:

Car <: Vehicle //it means car is subtype of vehicle Fruit >: Mango //fruit is super type of the mango 

That means we can put an instance of car on vehicle stack. And an instance of mango on the stack of Fruit.

Map[String, Dataset[_ >: TypeA with TypeB <: Serializable with Product]] 

This line means that Dataset is of type where. _ is super type of TypeA with TypeB is the subtype of the Serializable.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that helped a lot. I was able to simplify the expression using this to Dataset[_ <: Serializable with Product] and it compiled correctly.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.