1

I want to access the Class Type name in order to specify the runtime type. For example

DAO<?> i  = DAO<?> DOA.class.forName(”Student”).newInstance();

What I am trying to do is I have a class called Student and at runtime I want to specify DAO. When running the code I get a ClassCastException.

Is there any way of getting the Student type instead of String so that the following can be done

DAO<?> = new DAO<Student>();

by specifying ?

user1348855
  • 155
  • 1
  • 2
  • 9
  • This question is similar to http://stackoverflow.com/q/75175/130224 and http://stackoverflow.com/q/356583/130224. – reprogrammer Dec 09 '12 at 21:10
  • This question is different. My question asks whether it is possible to instantiate a unknown type. So DAO i = new DAO() but I want it generic so that DAO> i = new DAO>(); I want unknown type to be filled in at runtime. – user1348855 Dec 10 '12 at 20:50
  • No, the type argument of DAO is not available at run-time due to type erasure. – reprogrammer Dec 10 '12 at 21:21

0 Answers0