Reading up about type erasure should help you understand this a bit better.
At runtime, the type parameters for a generic class are erased. Meaning, as cletus said, generics in Java are basically syntactic sugar - they are only a compile-time feature.
Since Spring is instantiate objects at run-time, it is actually free to instantiate a Dao
of any type - and actually, there is nothing stopping it from creating a Dao
and passing in Student
types in some methods and Teacher
types in another.
So basically the answer is, Spring has no idea that the Dao
type is meant to be parameterized and can't do anything with it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…