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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:52:41+00:00 2026-05-25T17:52:41+00:00

I know this isn’t a good question to ask and I might get cursed

  • 0

I know this isn’t a good question to ask and I might get cursed to ask it but I cannot find any place to get help on this question

Below is a Generic class that appeared in my interview question (which I have already failed). The question was to tell what this Class declaration is doing and in what circumstances this could be used for ?

I have very limited understanding of Generic programming but I understand that ‘T’ is Type and ‘extends’ here means that the Type should have inherited ‘SimpleGenericClass’ but I do not understand the ‘?’ at the end and in what circumstances this Class could be potentially used for

public abstract class SimpleGenericClass<T extends SimpleGenericClass<?>> {

}
  • 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-25T17:52:41+00:00Added an answer on May 25, 2026 at 5:52 pm

    First, because the class SimpleGenericClass is abstract, it is meant to be subclassed.

    Second, it is a generic class which means that inside the class somewhere you will almost assuredly be using the generic parameter T as the type of a field.

    public abstract class SimpleGenericClass<T...> {
        T x;
    }
    

    Now the first interesting thing here is that T is bounded. Because it is declared as T extends SimpleGenericClass<?> it can only be SimpleGenericClass<?> or some subclass of SimpleGenericClass<?>. You also asked about thr ?. That’s known as a wildcard and there is a pretty good explanation of it at the Java Tutorial on Wildcards. In your case we would say this is a “SimpleGenericClass of unknown.” It is needed in Java because SimpleGenericClass<Object> is NOT the superclass of SimpleGenericClass<String>, for example.

    The second interesting thing though is that since T is a SimpleGenericClass of some sort, your class is more than likely defining recursive structures. What comes to my mind are trees (think of expression trees) where SimpleGenericClass is the (abstract) node type, designed to be subclassed with all kinds of specialized node types.

    UPDATE This SO question on self-bounded generics might be helpful to you.

    UPDATE 2

    I went ahead and put together some code that illustrates how this can be used. The app doesn’t do anything but it does compile and it shows you how the generic bounds can supply some possibly-meaningful constraints.

    public abstract class Node<T extends Node<?>> {
        public abstract T[] getChildren();
    }
    
    class NumberNode extends Node {
        int data;
        public Node[] getChildren() {return new Node[]{};}
    }
    
    class IdentifierNode extends Node {
        int data;
        public Node[] getChildren() {return new Node[]{};}
    }
    
    class PlusNode extends Node {
        NumberNode left;
        NumberNode right;
        public NumberNode[] getChildren() {return new NumberNode[]{};}
    }
    

    The nice thing here is that NumberNode[] is a valid return type for PlusNode.getChildren! Does that matter in practice? No idea, but it is pretty cool. 🙂

    It’s not the greatest example, but the question was rather open ended (“what might such a thing be used for?”). There are other ways to define trees, of course.

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

Sidebar

Related Questions

I know this isn't the best place to put this question but here it
I know this isn't strictly a programming question but y'all must have experienced this.
I know this isn't strictly speaking a programming question but something I always hear
I know this question isn't directly programming related, but since I want to be
I know this isn't a direct programming question, but's it's kinda relevant as I'm
I know this isn't the right place to ask about this specific vague problem,
I know this isn't exactly a programming question, but there may be some libraries/algorithms
Ok... First off, I know this isn't a new question. But, for some reason
I know this isn't strictly a programming question, but it is related to git.
I know this isn't exactly a programming question per se, but rather a settings

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.