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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:35:14+00:00 2026-05-24T22:35:14+00:00

I am having an error while compiling the following code involving a few generics:

  • 0

I am having an error while compiling the following code involving a few generics:

public abstract class State<T extends HasAState<? extends State<T>>>{
    protected T parent;

    public void setParent(){ // It's been simplified for the sake of the question!
        parent.removeState(this); // Error here!
        this.parent = parent;
        parent.addState(this);    // Error here!
    }
}

public interface HasAState<T extends State<? extends HasAState<T>>> {
    public void addState(T state);
    public void removeState(T state);
}

The errors are: The method removeState(capture#1-of ? extends State<T>) in the type HasAState<capture#1-of ? extends State<T>> is not applicable for the arguments (State<T>)

Actually what I would like to have is something like: class A implements HasAState and class B extends State<A> where B has a reference to A and can call A.addState(B) (only because B extends State<A>) and where A can call B.setParent(this).

How should I declare my classes so that what I intend to do work?

Thanks

  • 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-24T22:35:15+00:00Added an answer on May 24, 2026 at 10:35 pm

    I agree with the comment of Eran Zimmerman. It seams that you need to rethink about what you want.

    Anyway I hope I have understand the problem right, so I changed the Parameter from one to tow, to describe the state and the hasAState separately.

    public abstract class State<S extends State<S, H>, H extends HasAState<S, H>>{
        protected H parent;
    
        public void setParent(){ 
            parent.removeState(this);
            this.parent = parent; //!!!this line has no effect!!!
            parent.addState(this);        
        }       
    }
    
    public interface HasAState<S extends State<S, H>, H extends HasAState<S, H>> {
        public void addState(State<S, H> state);
        public void removeState(State<S, H> state);
    }
    

    This code compiles! — be aware of the warning for the second line in setParent.

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

Sidebar

Related Questions

I`m having the following error . Why am I having this error and how
I'm currently having following error message when executing a .sql file with about 26MB
I get the following error while performing the following commmand of adding rubygems.orgs as
Having problems compiling this class. I'm working through a book on java and this
I'm having a bit of an odd problem while trying to compile some code
We are having one problem while compiling with 64bit dlls. We are having lots
I have a code in which am trying to use outportb(), but while compiling
here is the part if having error. Fatal error: Using $this when not in
I'm having an error where I am not sure what caused it. Here is
I am having an error: Error 2 'int[]' does not contain a definition for

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.