Initialize a type variable with dynamic / concrete type
问题 I am learning Scala and I was trying to create a type class to solve the "Every animal eats food, but the type of food depends on the animal" problem. I have an Eats type class with context bounds: trait Eats[A <: Animal, B <: Edible] object Eats { def apply[A, B]: Eats[A, B] = new Eats[A, B] {} } with both Animal and Edible being abstract classes. The (reduced) Animal interface looks something like this abstract class Animal { type This // concrete type def eat[A <: Edible](food: A)(implicit