Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9153573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:17:40+00:00 2026-06-17T12:17:40+00:00

I am new to Java language. I have a case there I want to

  • 0

I am new to Java language. I have a case there I want to create a list dynamically.
e.g.

 public List getData(String classname)
{
   List<classname> ob = querywithParams.list();
    return ob;
 }

I will call this function like

List<Student> ob=getData("Student");

How can achieve this thing in Java? I need this for creating a common DB Adapter for HQL execution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:17:41+00:00Added an answer on June 17, 2026 at 12:17 pm

    try this

        @SuppressWarnings("unchecked")
        public <T>  List<T> getData(String classname, Class<T> pClass)
        {
           List<T> ob = querywithParams.list();
            return ob;
         }
    

    I don’t see you using the string classname in your method so you might as well remove it (If you wanted that just to specify the class type).
    So if you remove the string param, an example invocation would of the form :

    @SuppressWarnings("unchecked")
    public <T>  List<T> getData(Class<T> pClass)
    {
       List<T> ob = querywithParams.list();
        return ob;
     }
    
    // example invocation from some other method
        List<Student> ob = getData(Student.class);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am still new to the Java language and libraries... i often use this
Eclipse and MyEclipse create new Java files with an extra blank line after the
SimpleDateFormat formatter = new SimpleDateFormat(ddMMyyyy_HHmmSS); String strCurrDate = formatter.format(new java.util.Date()); String strfileNm = Cust_Advice_
I have started learning Java language for Android Application developement. As per my understanding
I'm new to Java, and have set myself a project to write so that
Edit: I should have probably mentioned that I am extremely new to Java programming.
I am new in Android app development and using Java language. My problem is
Now there is a new requirement. I have got some adhoc work at hand.
I have the following example classes in Java: public class A { } public
Before the introduction to generics to the Java language I would have written classes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.