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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:54:29+00:00 2026-06-13T23:54:29+00:00

Before I describe my problem let my say that I suspect I might simply

  • 0

Before I describe my problem let my say that I suspect I might simply lack the correct terms to search for, and that’s why my searches here on stackoverflor haven’t been fruitful. So links to answers would also be very much appreciated.

Im trying to make a library that has a Factory, lets call it “MyFactory”. MyFactory has a method that returns objects of the abstract class “MySuper”, but also one that exposes the avilable subclasses to “MySuper”. The library is intended to be expanded on a lot, so subclasses of “MySuper” will be added often, and then library will be recompiled, and dumped into a library folder of the application that uses it.

What I want is to be able to add a subclass of “MySuper” to the library, and have “MyFactory” become aware of it, preferebly without having to do anything else than create a new sublass of “MySuper”..

So far I use reflection to make “MyFactory” create new instances of a “MySuper” type, by giving the class name to a method, like this:

public MySuper getSuperObject(String name) {
    return (MySuper) Class.forName("my.package." + name).newInstance(); }

But how can I get the factory to expose alle the “MySuper” classes as f.x. a List of String, so the applications that use the library know what they can call? Can I iterate the content of a package?

I’m open for solutions, the most important part is that in the future it should be very hassle free to add new “MySuper” sub-classes..

Thanks 🙂

UPDATE:

I just want to note that I have found a nice Java library that handles reflection in an easy way, and lets you search for subtypes of a specific class. So my problem can be solved with that library (I have tested it). Here is a link: http://code.google.com/p/reflections/

  • 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-13T23:54:30+00:00Added an answer on June 13, 2026 at 11:54 pm

    You are looking for a Generic Factory Pattern. Something like..

    public static <T extends MySuper> T createDocument(Class<T> subClazz) throws InstantiationException, IllegalAccessException {
            return subClazz.newInstance();
        };
    

    You may google for Generic Factory Pattern and you will find lots of examples.

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

Sidebar

Related Questions

Before I describe my problem, it might actually make it clearer if I start
Before I describe my problem, here is a description of the program (IHExplorer.exe) I'm
Before asking the question let me preface with the fact that I am new
Before going to describe my problem first,I would like to define definitions of Decorator
This is a difficult problem to describe so please let me know if anything
Before going into the problem, I thought it'd be best to describe what I'm
The Problem Before I describe my current setup I will describe my problem. I
Let's say you have a form with a component that displays data from a
I have the following rspec: require 'spec_helper' describe KnowledgesController do before (:each) do @knowledge
before I start I want to point out that I tagged this question as

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.