I have a class that looks like this:
class Dao<T>{ ... }
I want to do this:
new Dao<Student>();
from the Spring XML configuration.
Can that be done? How?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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
Daoof any type – and actually, there is nothing stopping it from creating aDaoand passing inStudenttypes in some methods andTeachertypes in another.So basically the answer is, Spring has no idea that the
Daotype is meant to be parameterized and can’t do anything with it.