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

  • Home
  • SEARCH
  • 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 4071264
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:44:06+00:00 2026-05-20T16:44:06+00:00

public class Test { private static Object createInstance(String classPath) { try { Class<?> tClass

  • 0
public class Test {
    private static Object createInstance(String classPath) {
        try {
            Class<?> tClass = Class.forName(classPath);
            if (tClass != null) {
                return tClass.newInstance();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @SuppressWarnings("unchecked")
    public final static <INPUT, OUTPUT> Filter<INPUT, OUTPUT> getFilter(String path) {
        return (Filter<INPUT, OUTPUT>) createInstance(path);
    }

    public final static <INPUT, OUTPUT> OUTPUT filter(String path, INPUT mes) {
        Filter<INPUT, OUTPUT> filter = getFilter(path);

        //How to check the INPUT and OUTPUT type here?
        //if(INPUT instanceof String){ ... } not work

        return filter.filter(mes);
    }
}

refer to my earlier question here

thanks for help 🙂

  • 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-05-20T16:44:06+00:00Added an answer on May 20, 2026 at 4:44 pm

    Other answer are certainly correct. Anyway i think you are doing something quite unusual.
    I’ll try to explain:

    Generics are use for static polymorphism. An instance of a generic type is determined at compile time.

    Constructs like instanceof are used to check dynamic type of an object at runtime, so if you are using them, you can simply avoid the use of generics.
    (You can use a generic Object as parameter for your function and then use instanceof to check its type)
    For example:

    public void method(Object o){
        if (o instanceof String){} //do what you want
        else ....
    }
    

    Typically, if you use generics, you are just trying to avoid that constructs. Typically a generic type can implements a well know interface, in a way that any operation performed upon that object into your filter method, could be performed for different types of objects implementing that interface and without knowing the specific type of objects involved.

    I don’t know exactly what are the polymorphic feature that you need, anyway you could try also something like that:

    public interface polymorphicObj{
         public method();
    }
    public class Filter<GENERIC implements polymorphicObj>{
    
         public filter(GENERIC obj){
               obj.method();   //you don't need to know of which specific type is polymorphicObj
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let say I have the following desire, to simplify the IConvertible's to allow me
I want the messagebox to only show if the number is equal to 0.
My question is about memory use and objects in actionscript 2. If I have
I have a project that adds elements to an AutoCad drawing. I noticed that
We manage a site for a medical charity. They have a number of links
I have found this example on StackOverflow: var people = new List<Person> { new

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.