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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:54:59+00:00 2026-05-15T09:54:59+00:00

Please see Java Enum definition and Why in java enum is declared as Enum<E

  • 0

Please see
Java Enum definition
and
Why in java enum is declared as Enum<E extends Enum<E>>
for general discussion. Here I would like to learn what exactly would be broken (not typesafe anymore, or requiring additional casts etc) if Enum class was defined as

public class Enum<E extends Enum> 

I’m using this code for testing my ideas:

interface MyComparable<T> {
    int myCompare(T o);
}

class MyEnum<E extends MyEnum> implements MyComparable<E> {
    public int myCompare(E o) { return -1; }
}

class FirstEnum extends MyEnum<FirstEnum> {}

class SecondEnum extends MyEnum<SecondEnum> {}

With it I wasn’t able to find any benefits in this exact case.

PS. the fact that I’m not allowed to do

class ThirdEnum extends MyEnum<SecondEnum> {}

when MyEnum is defined with recursion is
a) not relevant, because with real enums you are not allowed to do that just because you can’t extend enum yourself
b) not true – pls try it in a compiler and see that it in fact is able to compile w/o any errors

PPS. I’m more and more inclined to believe that the correct answer here would be “nothing would change if you remove the recursive part” – but I just can’t believe that.

  • 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-15T09:55:00+00:00Added an answer on May 15, 2026 at 9:55 am

    I believe that a compelling reason to do that is that it makes the code in the MyEnum class more typesafe.

    Consider that the recursive part makes such a thing possible:

    class MyEnum<E extends MyEnum<E>> {
        private Thing<E> util1() { return someObject }
        private void util2(E e) {}
        public int method(E o) { 
            Thing<E> thingy = o.util1(); 
            // You can call the util1 method on o and get a type safe return element.
            E o1 = // I don't care how you get a parametrized E object.
            o.util2(o1);
            // You can call the util2 method with a typesafe parameter.
        }
    }
    

    In short, that recursivity lets you put typesafe methods in the Enum class that you can call on any E element, and these calls will be typesafe.

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

Sidebar

Related Questions

Please see working code here: http://jsfiddle.net/hrnDG/6/ I would like to modify this code so
Please see demo here: http://jsfiddle.net/mA6qm/1/ (expand console) Why aren't events being sent or received
Please see here , at the end of the post, the 70px author image
I'm making a torpedo game for school in java with swing gui, please see
I have two tab separated files (please see the examples below): File 1 Java
UPDATE: Please see https://softwarerecs.stackexchange.com/questions/71464/java-library-to-insert-invisible-text-into-a-pdf instead. I want to insert invisible text into an existing
please see follow pic. enter link description here i want when i click on
Well.. it seems like enum classes in Java are a lot more versatile than
Please see the following block of code import java.awt.Color; import java.awt.Dimension; import javax.swing.JFrame; import
in java i know that final variables value cannot be changed. please see the

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.