Creating a list of objects whose class is known dynamically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • krishna81m
    New Member
    • Oct 2007
    • 25

    Creating a list of objects whose class is known dynamically

    I am unable to create a list of objects dynamically. I run a SQL query on the database and populate objects of types that I also know aprior. I read the query as a string, run it on the database and want to be able to populate these objects of classes whose names are known to me also based on the type of the query. In this query, SomeClass is a variable.

    Class myClass = Class.forName(" SomeClass");
    Object myClassObj = myClass.newInst ance(null);

    When I say,

    List<myClassObj > myClassObjList = null;
    myClassObjList = somDao.getmyLis t(qry);

    I get an error, "myClassObj cannot be resolved to a type". This is very important as in my case I have a dynamically created query that is run on the database to create objects of specific type in advance and I am sending these list of objects to a jsp page for display and other purposes.

    Thanks in advance.

    Regards
    Kris
    Last edited by krishna81m; Feb 20 '08, 04:29 AM. Reason: change
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    Crosspost: http://forum.java.sun.com/thread.jspa?threadID=5266170

    Comment

    Working...