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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:25:48+00:00 2026-05-10T19:25:48+00:00

I thought I understood Java generics pretty well, but then I came across the

  • 0

I thought I understood Java generics pretty well, but then I came across the following in java.lang.Enum:

class Enum<E extends Enum<E>> 

Could someone explain how to interpret this type parameter? Bonus points for providing other examples of where a similar type parameter could be used.

  • 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. 2026-05-10T19:25:49+00:00Added an answer on May 10, 2026 at 7:25 pm

    It means that the type argument for enum has to derive from an enum which itself has the same type argument. How can this happen? By making the type argument the new type itself. So if I’ve got an enum called StatusCode, it would be equivalent to:

    public class StatusCode extends Enum<StatusCode> 

    Now if you check the constraints, we’ve got Enum<StatusCode> – so E=StatusCode. Let’s check: does E extend Enum<StatusCode>? Yes! We’re okay.

    You may well be asking yourself what the point of this is 🙂 Well, it means that the API for Enum can refer to itself – for instance, being able to say that Enum<E> implements Comparable<E>. The base class is able to do the comparisons (in the case of enums) but it can make sure that it only compares the right kind of enums with each other. (EDIT: Well, nearly – see the edit at the bottom.)

    I’ve used something similar in my C# port of ProtocolBuffers. There are ‘messages’ (immutable) and ‘builders’ (mutable, used to build a message) – and they come as pairs of types. The interfaces involved are:

    public interface IBuilder<TMessage, TBuilder>   where TMessage : IMessage<TMessage, TBuilder>    where TBuilder : IBuilder<TMessage, TBuilder>  public interface IMessage<TMessage, TBuilder>   where TMessage : IMessage<TMessage, TBuilder>    where TBuilder : IBuilder<TMessage, TBuilder> 

    This means that from a message you can get an appropriate builder (e.g. to take a copy of a message and change some bits) and from a builder you can get an appropriate message when you’ve finished building it. It’s a good job users of the API don’t need to actually care about this though – it’s horrendously complicated, and took several iterations to get to where it is.

    EDIT: Note that this doesn’t stop you from creating odd types which use a type argument which itself is okay, but which isn’t the same type. The purpose is to give benefits in the right case rather than protect you from the wrong case.

    So if Enum weren’t handled ‘specially’ in Java anyway, you could (as noted in comments) create the following types:

    public class First extends Enum<First> {} public class Second extends Enum<First> {} 

    Second would implement Comparable<First> rather than Comparable<Second>… but First itself would be fine.

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

Sidebar

Ask A Question

Stats

  • Questions 270k
  • Answers 270k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer See ysth's answer ... I failed to realize that the… May 13, 2026 at 1:34 pm
  • Editorial Team
    Editorial Team added an answer I'm not really sure what you're doing here: $("#alert").slideUp().delay(1000); jQuery… May 13, 2026 at 1:34 pm
  • Editorial Team
    Editorial Team added an answer Is this the droid you were looking for? public Form1()… May 13, 2026 at 1:34 pm

Related Questions

Sorry for the generic title, will change it once I understand the source of
I encounter a totally strange behavior of the Java compiler. I can't cast a
I'm having a bit of trouble trying to get class variables to work in
I'm developing a LoB application in Java after a long absence from the platform

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.