When should I use generics to define relationships between types?

前端 未结 6 1365
隐瞒了意图╮
隐瞒了意图╮ 2020-12-08 21:50

Getting into a little bit of confusion here when to use generics. I\'ve looked at Java Generics? but still have a few questions.

Say I have:

public          


        
6条回答
  •  遥遥无期
    2020-12-08 22:04

    I'd tend to favor composition (what you're calling dynamic binding), especially in the case you use. A person is not a type of ICar, so using the generics here is kind of weird (to me anyway). I'd use generics as a way of saying "A container for ICar", as in Garage although in that case I might just use a collection type as a variable, or extend the collection type if really needed.

提交回复
热议问题