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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:40:31+00:00 2026-05-27T17:40:31+00:00

Pretty trivial Java question. This code has an error: public abstract class SubTypeDependentEditor<T> implements

  • 0

Pretty trivial Java question. This code has an error:

public abstract class SubTypeDependentEditor<T> implements Editor<T> {
  protected abstract Editor<? extends T> getEditorFor(T obj);       

  public void edit(T obj) {
    Editor<? extends T> editor = getEditorFor(obj);
    editor.edit(obj); // ERROR IS HERE
  }
}

What’s the right way one should fix it?

The idea of T is basically just a type of classes’ hierarchy root, so given a hierarchy like this:

class Entity {}
class EntityA extends Entity {}
class EntityB extends Entity {}

one will have T set to Entity and getEditorFor(T obj) is responsible for returning Editor<X> where X depends on obj‘s concrete type and always Is-A T. So, if you have SubTypeDependentEditor<Entity>, getEditorFor(T obj) returns Editor<EntityA> when obj is EntityA and Editor<EntityB> when obj is EntityB.

Any chance this can be implemented without warnings?

Update:

protected abstract Editor<? extends T> getEditorFor(T obj);     

Can basically have any other signature, but the code that implements that code only has objects that are Editor<X>, so in case this method returns Editor<T> I’m not sure how to implement getEditorFor(T obj).

  • 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-27T17:40:32+00:00Added an answer on May 27, 2026 at 5:40 pm
    protected abstract Editor<? extends T> getEditorFor(T obj);
    

    means that getEditorFor() returns an editor for an unknown sub-type of T.

    You can’t pass use any value of type T with that result since the compiler cannot prove that obj works with the same concrete sub-type of T that is obj‘s type.

    The solution is to change

    protected abstract Editor<? extends T> getEditorFor(T obj);
    

    to

    protected abstract Editor<? super T> getEditorFor(T obj);
    

    which says that getEditorFor returns an editor that edits an unknown type that includes obj.

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

Sidebar

Related Questions

Has anyone managed to extend a GridView with default sorting? This seems pretty trivial
I am pretty new to web work. I apologize if this question is trivial
All, I'm pretty new to AS3, so this is probably a very trivial question.
This is pretty trivial, but I noticed on SO that instead of an offset
A pretty silly trivial question. The canonical example is f = open('filename') , but
Pretty sure this question counts as blasphemy to most web 2.0 proponents, but I
Pretty simple question: When i have a persistable object, it usually has a property
Pretty all in question... I'm looking for batch script, code or library which allows
I believe this is pretty trivial but I can't get it to work. I
This should be a pretty trivial one. Can C# return a type that is

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.