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 8780105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:57:34+00:00 2026-06-13T19:57:34+00:00

Here is the situation: interface A{}//interface for entities class B implements A{}//entity B class

  • 0

Here is the situation:

interface A{}//interface for entities
class B implements A{}//entity B 
class C implements A{}//entity C 

abstract class AR<E extends A>{}//generate list of E via a file,this will be done after the construct func.
class BR extends AR<B>{}
class CR extends AR<C>{}

Now I want to maintain:
Map<String,List<A>> data;//<filepath+filename, list of entities in file>

The func. blow will return the list based on the fileAddr:

<E extends A,R extends AR<E>> List<A> getList(String fileAddr)
{
 if(data.containsKey(fileAddr))
  return data.get(fileAddr);
 else
 {
  AR<E> reader=new R(fileAddr);//generate a list of E via this file
  List<E> values=reader.getValues();
  data.put(fileAddr,values);
  return values;
 }
}  

But this doesn’t work,and new R(fileAddr) is not supported.

So how to implement getList() func. based the spec. above.

  • 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-13T19:57:35+00:00Added an answer on June 13, 2026 at 7:57 pm

    You cannot use new to generate an instance of a type parameter. The technical reason is that the type information has been erased by the time that getList is executed. Anyway, the Java language does not permit it.

    One way around the problem is to pass in a factory object that can create the required instance.

    Another way around it is to pass the parameter type’s Class object as an argument, and then create the instance reflectively; e.g. something like this:

    <E extends A,R extends AR<E>> List<A> getList(String fileAddr, Class<R> rClass)
    {
     if(data.containsKey(fileAddr))
      return data.get(fileAddr);
     else
     {
      Constructor<R> ctor = rClass.getConstructor(String.class);
      R reader=ctor.newInstance(fileAddr);
      List<E> values=reader.getValues();
      data.put(fileAddr,values);
      return values;
     }
    }
    

    (There will be a bunch of exceptions to deal with …)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my situation: interface Icontainer{ string name(); } abstract class fuzzyContainer : Icontainer{ string
Here's the situation: I have an abstract class with a constructor that takes a
Here is the situation, I have UIViewController class with a UITableView outlet. I would
Here's the situation… So I've created a Node.js module that acts as an interface
Well, here's the situation: I've got... a custom class with an UIImageView -property, let's
I have a package P with public interface I public class S1 extends Foo
Here's my situation: We have an outside provider that will be pushing XML files
Here is the situation. I've got the following interfaces: public interface Parent { }
Here is my situation: I have an interface that each of my controls use
So here is my situation. I have a class ABCAdapter. Here I have declared

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.