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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:10:53+00:00 2026-06-10T10:10:53+00:00

I’ve got a framework here that uses an object to maintain state between other

  • 0

I’ve got a framework here that uses an object to maintain state between other objects as they interact with it. I was hoping that the objects that interact with the state (“Actions”) could generically accept a type of interface, which the State object would implement, but I’m having trouble making this work.

I want to define the framework object itself in terms of a specific state implementation (or interface), and be able to add Actions to it, as long as they accept the defined state, either directly or through an interface that the state implements.

As I understand it, the <? super S> definition means “some type that is a parent of S”, but I am not sure that an Interface that is implemented by S fits this description, as it’s not exactly a parent class.

Here’s an example (not exactly compiling code):

Class Framework<State> {
    addAction(Action<? super State> a) {} // adds to a list of actions to be run

    run(State s) {
        for(Action<? super State> a : actions) {
            a.perform(s);
        }
    }
}

Interface IState1 {}

Interface IState2 {}

Interface Action<State> {
    public void perform(State s);
}

Class Action1 implements Action<IState1> {}

Class Action2 implements Action<IState2> {}

Class CombinedState implements IState1, IState2 {}

public static void run() {
    Framework<CombinedState> f = new Framework<CombinedState>();

    // add is expecting Action<? super CombinedState> but getting Action<IState1>
    f.add(new Action1()); // This doesn't seem to work
    f.add(new Action2());

    f.run(new CombinedState());
}

For the purposes of generics, do Interfaces count as parent classes? Is there any way to implement this that doesn’t require reflection?

  • 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-10T10:10:54+00:00Added an answer on June 10, 2026 at 10:10 am
    import java.util.ArrayList;
    
    class State{}
    
    class Framework<State> 
    {
        public ArrayList< Action< ? super State > >actions = new ArrayList< Action< ?super State > >();
    
        void add(Action<? super State> a) {
    
            actions.add(a);
    
        } 
    
        void doRun(State s) {
            for(Action<? super State> a : actions) {
                a.perform(s);
            }
        }
    }
    
    interface IState1 {}
    
    interface IState2 {}
    
    interface Action<State> {
        public void perform(State s);
    }
    
    class Action1 implements Action<IState1> {
        public void perform( IState1 s )
        {
            System.out.println("Do something 1");
        }
    }
    
    class Action2 implements Action<IState2> {
    
        public void perform( IState2 s )
        {
            System.out.println("Do something 2");
        }   
    }
    
    class CombinedState implements IState1, IState2 {}
    
    class Untitled {
        public static void main(String[] args) 
        {
             Framework<CombinedState> f = new Framework<CombinedState>();
    
                // add is expecting Action<? super CombinedState> but getting Action<IState1>
                f.add(new Action1()); // This doesn't seem to work
                f.add(new Action2());
    
                f.doRun(new CombinedState());
        }
    }
    

    This runs in CodeRunner on OSX.

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
i got an object with contents of html markup in it, for example: string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.