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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:31:05+00:00 2026-06-10T23:31:05+00:00

Java is not allowing me to add a subclass of the Type declaration in

  • 0

Java is not allowing me to add a subclass of the Type declaration in this class

public class Exam<T> {

    public  void set(Holder<? super T> hold){

    }
    public  T get(Holder<? extends T> holder){ return holder.get();}


    public static void main (String[] args){
        Exam<Question> eq = new Exam<Question>();
        eq.set(new Holder<Identification>());
    }
}

Where Identification is a subclass of Question.

and this how my holder class looks like

public class Holder<T> {
    T item;

    public void set(T item){ this.item = item; }
    public T get(){return item;}
}

ERROR

The method set(Holder<? super Question>) in the type Exam<Question> is not applicable for the arguments (Holder<Identification>)
  • 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-10T23:31:06+00:00Added an answer on June 10, 2026 at 11:31 pm

    The error looks pretty self-explanatory to me – the set method expects a Holder<? super Question> and you’re trying to give it a Holder of something that is a subclass of Question. As written, Exam.set could take a Holder<Object>, for example, but not a Holder<Identification>.

    A good way to think about extends and super in generics is in terms of assignment: T extends Foo will accept any type T that you could use on the right hand side of an assignment to Foo without casting, i.e.

    Foo something = new T();
    

    (treat this as pseudocode – I know you’re not really allowed to new a type varaible). Conversely, T super Foo accepts any T you could use on the left hand side of an assignment without casting:

    T myThing = new Foo();
    

    In your specific example, Identification i = new Question() isn’t legal without a cast, so a Holder<? super Question> parameter can’t accept a Holder<Identification> value.

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

Sidebar

Related Questions

In this Java code: public class Main { public static void main(String[] args) {
Why does Java not have a file copy method? This seems like such an
Why are some exceptions in Java not caught by catch (Exception ex) ? This
Is there a reason why java does not have a class which allows both
I am very disappointed in Java for not allowing the following code to move
public void wahey(List<Object> list) {} wahey(new LinkedList<Number>()); The call to the method will not
Java is not allowing inheritance from multiple classes (still it allows inheritance from multiple
Is there any built-in functionality for classical set operations on the java.util.Collection class? My
In java, is there ever a case for allowing a non-abstract class to be
Previously Id asked this question Putting a simple expression language into java about allowing

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.