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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:31:55+00:00 2026-06-11T06:31:55+00:00

Hi I am trying to create a generic method that takes in a parameter

  • 0

Hi I am trying to create a generic method that takes in a parameter which type is an abstract parameterised class. Inside the method I want to create a instances of the passed parameter given it is a subclass of the abstract type since we cannot instantiate abstract classes.

However I am having some issues. And the error message says the RuleType cannot be resolved to a type which is not surprising anyway but I don’t know how can I accomplish this.
My current code is below.

private <F extends AbstractRule<T>, T> void applyRyle(F cRule,ArrayList<T> aFeatures)
{

    Class RuleType = cRule.getClass();


    // if the parameter passed is a subclass of AbstractRule create some objects
    if(!RuleType.getSuperclass().getName().equals("AbstractRule"))
    {
        ArrayList<RuleType<T>> aRules = new ArrayList<RuleType<T>>();
        for(int i = 0; i < 10; i++)
        {

            RuleType<T> aRule= new RuleType<T(pattern.getMatrices().size(), 2,aFeatures);
            aRule.initialise(aRule.getMaxLocalLevel());
            aRules.add(aRule);
        }
    }
  • 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-11T06:31:57+00:00Added an answer on June 11, 2026 at 6:31 am

    Some of this can be done by using reflection:

    private <F extends AbstractRule<T>, T> void applyRyle(F cRule, ArrayList<T> aFeatures)
    {
         Class<? extends F> ruleType = cRule.getClass();
         // if the parameter passed is a subclass of AbstractRule create some objects
         if(! ruleType.getSuperclass().getName().equals("AbstractRule"))
         {
             ArrayList<? extends F> aRules = new ArrayList<? extends F>();
             for(int i = 0; i < 10; i++)
             {
                 F aRule =
                     ruleType
                         .getConstructor(int.class, int.class, ArrayList.class)
                         .newInstance(pattern.getMatrices().size(), 2, aFeatures);
                 aRule.initialise(aRule.getMaxLocalLevel());
                 aRules.add(aRule);
             }
         }
    

    though it’s probably not the best way to accomplish what you really want.

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

Sidebar

Related Questions

I am trying to create a generic method that will read an attribute on
I'm trying to create a generic class in PHP that will provide a way
I am trying to create a generic class which new's up an instance of
I am currently trying to create a generic instance factory for which takes an
I am trying to create a method that takes a DataTable or a DataRowCollection
I want to create a helper method that can take in ANY type of
I am trying to create a generic method that will retrieve an item by
I'm trying to create a generic method that will return a predicate to find
I'm trying to create a generic method where the type is a generic interface.
I'm trying to create a generic extension method, that works on typed data tables

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.